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;

 

相关文章:

  • 2022-01-17
  • 2022-01-29
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2021-08-01
相关资源
相似解决方案