这个是用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 |
+------+-------+
会了 感觉挺简单 不会之前 真的是怎么都搞不定 总之搞定了 希望遇到这种问题的人能看到它解决把
最后
以上就是年轻凉面最近收集整理的关于mysql查询每年每个月的数据_mysql 查询一年中每个月份的数据量的全部内容,更多相关mysql查询每年每个月的数据_mysql内容请搜索靠谱客的其他文章。
发表评论 取消回复