Hello,
I my dataset is like following
sql:
select quarter, sum(amount) as amount from table1 group by quarter
then I get the dataset
field: quarter,amount
date: quarter1,100
quarter2,500
Is it possible to get my report from the dataset above.
my report:
quarter,amount
quarter1,100
quarter2,500
quarter3,0
quarter4,0
thanks!This is possible if you have a time (or quarter) table in your database:
SELECT
q.quarter,
ISNULL(t1.amount,0) as amount
FROM quarters q
LEFT JOIN table1 t1
ON q.quarter = t1.quarter
|||
thank you for reply
I can't get the tabe quarters ...
|||Use this SQL:
SELECT
q.quarter,
ISNULL(t1.amount,0) as amount
FROM quarters q LEFT JOIN
(SELECT 'quarter1' AS quarter UNION SELECT 'quarter2' AS quarter UNION SELECT 'quarter3' AS quarter UNION SELECT 'quarter4' AS quarter) AS qrt
ON quarters.quarter = qrt.quarter
This will work.
Please mark the post as answer.
Shyam
|||
In order to more easily manage date groupings (weeks, months, quarters, years, etc.) it is a VERY good idea to have a Calendar table in your database. Having a Calendar table makes tasks such as this one very simple.
Here is additional information about creating and using a Calendar table.
Datetime -Calendar Table
http://www.aspfaq.com/show.asp?id=2519
No comments:
Post a Comment