例:表index_user ,字段in_date ,分别按周、日、月分组 -- in_date为时间格式 SELECT DATE_FORMAT(in_date,"%Y-%u") weeks,COUNT(1) CO
例:表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
--结束END--
本文标题: Mysql按日期时间分组
本文链接: https://lsjlt.com/news/6480.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0