这个是用mid()函数 截取字符串
mysql> select count(*) as '数量',mid(time,1,7) as month from my_add where time between '2015-01-01 00:00:00' and '2016-01-01 00:00:00' group by month;
+------+---------+
| 数量 | month |
+------+---------+
| 2 | 2015-01 |
| 1 | 2015-08 |
| 1 | 2015-09 |
| 1 | 2015-10 |
| 1 | 2015-11 |
| 2 | 2015-12 |
+------+---------+
这是另一种方法date_format()
mysql> select count(*) as '数量',date_format(time,'%m') as month from my_add group by month;
+------+-------+
| 数量 | month |
+------+-------+
| 1 | NULL |
| 3 | 01 |
| 1 | 08 |
| 1 | 09 |
| 1 | 10 |
| 1 | 11 |
| 2 | 12 |
+------+-------+
会了 感觉挺简单 不会之前 真的是怎么都搞不定 总之搞定了 希望遇到这种问题的人能看到它解决把