I am trying to count the records in my table and group them per date. My current query looks something like the following:
SELECT
count(*),
MONTH(time) as month,
YEAR(time) as year
FROM
myTable
GROUP BY
month, year
ORDER BY
year, month
This works, except that I would also like to get a count for months where no records exists.
Could anyone offer advice/suggestions on how to accomplish this?
The simplest way to do this in MySQL is to create a table called
monthsthat lists all the months you are interested in and use a LEFT JOIN to your table.However since this is mostly a presentation issue it is often easier just run the query as you are already doing and transform the result in the client (e.g. PHP).