Subject | Re: Crosstab |
---|---|
Author | Petr Jakes |
Post date | 2006-05-07T02:31:48Z |
MY_YEAR CATEGORY
2000 1
2000 4
2000 2
2000 4
2000 1
2000 0
2001 3
2003 3
2003 2
2003 1
SELECT (MY_TABLE.my_year),
sum (case MY_TABLE.category when '0' then 1 else 0 END) as "categ 0",
sum (case MY_TABLE.category when '1' then 1 else 0 END) as "categ 1",
sum (case MY_TABLE.category when '2' then 1 else 0 END) as "categ 2",
sum (case MY_TABLE.category when '3' then 1 else 0 END) as "categ 3",
sum (case MY_TABLE.category when '4' then 1 else 0 END) as "categ 4"
FROM MY_TABLE
group by 1, order by 1
I am using "year" for the simplicity of the example, if your "dates"
are timestamps you can use EXTRACT and '|' as was suggested in
previous postings.
HTH
Petr Jakes
2000 1
2000 4
2000 2
2000 4
2000 1
2000 0
2001 3
2003 3
2003 2
2003 1
SELECT (MY_TABLE.my_year),
sum (case MY_TABLE.category when '0' then 1 else 0 END) as "categ 0",
sum (case MY_TABLE.category when '1' then 1 else 0 END) as "categ 1",
sum (case MY_TABLE.category when '2' then 1 else 0 END) as "categ 2",
sum (case MY_TABLE.category when '3' then 1 else 0 END) as "categ 3",
sum (case MY_TABLE.category when '4' then 1 else 0 END) as "categ 4"
FROM MY_TABLE
group by 1, order by 1
I am using "year" for the simplicity of the example, if your "dates"
are timestamps you can use EXTRACT and '|' as was suggested in
previous postings.
HTH
Petr Jakes