MySQL ~ COUNT(*) and GROUP BY year and month

SQL

SELECT COUNT(*) AS count, YEAR(date) AS year, MONTH(date) AS month FROM news GROUP BY YEAR(date), MONTH(date) ORDER BY year DESC


Result
count year month
4 2010 1
1 2010 2
4 2010 3
6 2010 4
6 2010 5
1 2009 3
3 2009 5
6 2009 6
4 2009 7
1 2009 8
4 2009 9
9 2009 10
2 2009 11
4 2009 12
1 2008 1
1 2008 3
1 2008 4
1 2008 5
5 2008 6
1 2008 7
8 2008 8
3 2008 9
3 2008 10
2 2008 11
3 2008 12
2 2007 3

沒有留言: