mysql按天,按周,按月,按季度,按年统计表中的数据
1.按天统计
SELECT count(id) id, DATE(create_time) create_time FROM tb_time GROUP BY DATE(create_time) ORDER BY DATE(create_time) DESC;
2.按周统计
SELECT count(id) id, WEEK(create_time) create_time FROM tb_time GROUP BY WEEK(create_time) ORDER BY WEEK(create_time) DESC;
2.按月统计
SELECT count(id) id, MONTH(create_time) create_time FROM tb_time GROUP BY MONTH(create_time) ORDER BY MONTH(create_time) DESC;
3.按年统计
SELECT count(id) id, YEAR(create_time) create_time FROM tb_time GROUP BY YEAR(create_time) ORDER BY YEAR(create_time) DESC;

浙公网安备 33010602011771号