按周 select DATE_FORMAT(create_time,'%Y%u') weeks,count(caseid) count from tc_case group by weeks; 按月 select DATE_FORMAT(create_time,'%Y%m') months,count(caseid) count from tc_case group by months; 按天 select DATE_FORMAT(create_time,'%Y%m%d')
Time字段以小时分组统计 select datepart(hour,time) hour,count(1) count from table where Similarity<75 group by datepart(hour,time) order by count desc From:https://www.cnblogs.com/xuejianxiyang/p/11202931.html 5分钟,半个小时,任意间隔分组分组 开发中遇到过问题就是对时间以半个小时分钟分组,如统计08:00-
group by DATE_FORMAT(createtime,'%Y-%m');//按月统计数据 group by DATE_FORMAT(createtime,'%Y-%m-%d');//按天统计数据 +---------------------------------+----------+ | DATE_FORMAT(createtime,'%Y-%m') | count(*) | +---------------------------------+----------+ | | |