| Mailing List | | Home | | MySQL General - General MySQL discussion | | MaxDB - Everything about MaxDB, formerly known as SAP DB | | MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP | | Java Help - Mostly related to the MySQL Connector/J driver | | ODBC - ODBC with the MySQL Connector/ODBC driver | | Perl - Perl support for MySQL with DBI and DBD::mysql | | MySQL++ - Programming with the C++ API to MySQL |
|
|
  | |  | SQL Group by months, return all months even if zero | SQL Group by months, return all months even if zero 2004-03-22 - By Harald Fuchs
Back In article <01e901c40fe0$e581da80$c90010ac@(protected) >,
"Terence " <terence@(protected) > writes:
> Hi,
> Is there a short way to return the results from a query grouped by months
> and return zero if no results found: eg:
> SELECT count(*) as total, monthname(col)
> FROM table
> GROUP BY monthname(col)
> To return:
> 5 - Jan
> 0 - Feb
> 3 - Mar
> 0 - Apr
> etc.
> Just wondering. I know the long way to do it, by quering each month one by
> one...
Create an auxiliary table containing either the month names or the
numbers 1..12 and LEFT JOIN your table to it.
--
MySQL General Mailing List
For list archives:
http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=mysql
@(protected)
|
|
 |