Elegant SQL solution: - Mailing list pgsql-sql

From Chris Gamache
Subject Elegant SQL solution:
Date
Msg-id 20030606162635.97132.qmail@web13807.mail.yahoo.com
Whole thread Raw
In response to Re: simulating partial fkeys..  (Bruno Wolff III <bruno@wolff.to>)
Responses Re: Elegant SQL solution:
Re: Elegant SQL solution:
Re: Elegant SQL solution:
List pgsql-sql
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     | 2343     | 9984     | 4035     | 25210    | 64312    | 933

I would like:
month | rows
-------+------1     | 2342     | 03     | 9984     | 4035     | 2526     | 07     | 08     | 09     | 010    | 64311
|012    | 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


pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: simulating partial fkeys.. [ATTN Developers please]
Next
From: "David Olbersen"
Date:
Subject: (long) What's the problem?