Elegant SQL solution:
От | Chris Gamache |
---|---|
Тема | Elegant SQL solution: |
Дата | |
Msg-id | 20030606162635.97132.qmail@web13807.mail.yahoo.com обсуждение исходный текст |
Ответ на | Re: simulating partial fkeys.. (Bruno Wolff III <bruno@wolff.to>) |
Ответы |
Re: Elegant SQL solution:
Re: Elegant SQL solution: Re: Elegant SQL solution: |
Список | 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 по дате отправления: