Mysql按日、周、月分组统计数据

我们需要对每天,每周,每月活跃用户进行统计,

1)按天统计:

select DATE_FORMAT(create_time,'%Y-%m-%d') days, count(id) count from user group by days; 

2)按周统计:

select DATE_FORMAT(create_time,'%Y-%u') weeks, count(id) count from user group by weeks; 

3)按月统计:

select DATE_FORMAT(create_time,'%Y-%m') months, count(id) count from user group by months; 

DATE_FORMAT 函数说明地址:https://www.w3school.com.cn/sql/func_date_format.asp

猜你喜欢

转载自blog.csdn.net/jack1liu/article/details/106415315