I have the following query in mysql:
SELECT title,
added_on
FROM title
The results looks like this:
Somos Tão Jovens 2013-10-10 16:54:10
Moulin Rouge - Amor em Vermelho 2013-10-10 16:55:03
Rocky Horror Picture Show (Legendado) 2013-10-10 16:58:30
The X-Files: I Want to Believe 2013-10-10 22:39:11
I would like to get the count for the titles in each month, so the result would look like this:
Count Month
42 2013-10-01
20 3013-09-01
The closest I can think of to get this is:
SELECT Count(*),
Date(timestamp)
FROM title
GROUP BY Date(timestamp)
But this is only grouping by the day, and not the month. How would I group by the month here?
Edit: And obviously if it matters to display the 1st day of the month in the results, you do the
DATE_FORMAT(timestamp, "%Y-%m-01")
thing mentioned in some other answers :)The best bet is to group it by YEAR and then by MONTH. See below
Could you try this?
Please, note that
MONTH()
can't differentiate '2013-01-01' and '2014-01-01' as follows.