I have a list of dates from table like this:
2014-05-21
2014-08-20
2014-06-03
2014-06-03
2014-05-24
2014-05-28
2014-05-24
2014-05-27
2014-08-20
2014-05-28
and so on.
I need to count the total grouped by month for each date like this: 05 = 6, 06 = 2, 08 = 2.
I am very noob in mysql, can you guys help me on how I should do this? Thanks.
3 Answers
2 Comments
Shah Erhan
Any idea on how do I count if it is not the same year?
M Khalid Junaid
@ShahErhan you can change group by to
group by year(date),month and for select month(date) month, year(date)try this query it would work, may be with some alteration
"select count(DATE_FORMAT(date_column, '%m')) form your_table group by date_coloumn"
or
"select count(*),DATE_FORMAT(date_column, '%m') form your_table group by date_coloumn"
2 Comments
Shah Erhan
I've tried your solution with some alteration but I can't get it right. The other answer works flawlessly. Thanks by the way.
A.B
i have a mistake in form instead of form, any ways purpose is achieved and thats great (Y)
YEAR(date)= 2014 in the query. Wait, that is wrong I guess.