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;
如果学武不是为了当武林盟主,那将毫无意义