Mysql按日期时间分组
例:表index_user ,字段in_date ,分别按周、日、月分组
-- in_date为时间格式
SELECT DATE_FORMAT(in_date,"%Y-%u") weeks,COUNT(1) COUNT FROM index_user GROUP BY weeks;
SELECT DATE_FORMAT(in_date,"%Y-%m-%d") days,COUNT(1) COUNT FROM index_user GROUP BY days;
SELECT DATE_FORMAT(in_date,"%Y-%m") months,COUNT(1) COUNT FROM index_user GROUP BY months
-- in_date为时间戳格式
SELECT FROM_UNIXTIME(in_date,"%Y%u") weeks,COUNT(1) COUNT FROM index_user GROUP BY weeks;
SELECT FROM_UNIXTIME(in_date,"%Y-%m-%d") days,COUNT(1) COUNT FROM index_user GROUP BY days;
SELECT FROM_UNIXTIME(in_date,"%Y%m") months,COUNT(1) COUNT FROM index_user GROUP BY months
以上是 Mysql按日期时间分组 的全部内容, 来源链接: utcz.com/z/533996.html