例:表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