There are so many (bad) ways to skin this cat... I'm looking for a more elegant
solution.
If I
SELECT date_part('month',rowdate) as month, count(*) as rows FROM mytable GROUP
BY month;
It might only return
month | rows
-------+------
1 | 234
3 | 998
4 | 403
5 | 252
10 | 643
12 | 933
I would like:
month | rows
-------+------
1 | 234
2 | 0
3 | 998
4 | 403
5 | 252
6 | 0
7 | 0
8 | 0
9 | 0
10 | 643
11 | 0
12 | 933
I could create a one-column table with values 1 - 12 in it, and select from
that table with a where clause matching "month". I could also create a view
"SELECT 1 UNION SELECT 2 UNION ..." and select against the view. There MUST be
a more elegant way to do this.
Any thoughts?
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faqs/FAQ.html