sql根据时间戳按年月日分组统计

sql根据时间戳按年月日分组统计,用于按日期分类:

create_time为时间格式(字段名create_time 根据自己表字段修改,数据库中存为201610071202)

SELECT DATE_FORMAT(create_time,'%Y%u') weeks,COUNT(id) COUNT FROM role GROUP BY weeks;

SELECT DATE_FORMAT(create_time,'%Y%m%d') days,COUNT(id) COUNT FROM role GROUP BY days;

SELECT DATE_FORMAT(create_time,'%Y%m') months,COUNT(id) COUNT FROM role GROUP BY months;

create_time为时间戳格式(字段名create_time 根据自己表字段修改,数据库中存为1474959640):

SELECT FROM_UNIXTIME(create_time,'%Y%u') weeks,COUNT(id) COUNT FROM role GROUP BY weeks;

SELECT FROM_UNIXTIME(create_time,'%Y%m%d') days,COUNT(id) COUNT FROM role GROUP BY days;

SELECT FROM_UNIXTIME(create_time,'%Y%m') months,COUNT(id) COUNT FROM role GROUP BY months;

posted @ 2022-01-18 10:02  何家有子初长成  阅读(916)  评论(0编辑  收藏  举报