以周一作为一周的开始, 使用mysql week行数模式5:
作为周划分的标准, 比如20170101是周天, week(20170101, 5) = 0,
分WEEK_IN_MONTH, 和WEEK_IN_YEAR两种情况进行分组:
WEEK_IN_YEAR:
# by sleest 2017/03/29 按每个日期所在一年中的第几周分组汇总SELECT WEEK(MY_DATE, 5)+1 AS WEEK_OF_YEAR, COUNT(1) AS COUNT,
GROUP_CONCAT(MY_DATE) AS INCLUDE_DATE
FROM (SELECT '2017-01-01' AS MY_DATE
UNION ALL
SELECT '2017-02-08'
UNION ALL
SELECT '2017-02-03'
UNION ALL
SELECT '2017-02-01'
UNION ALL
SELECT '2017-01-21') TMP
GROUP BY WEEK(MY_DATE, 5) + 1
结果:
WEEK_IN_MONTH:
# by sleest 2017/03/29 按每个日期所在每个月的第几周分组汇总SELECT WEEK(MY_DATE, 5) - WEEK(DATE_SUB(MY_DATE, INTERVAL DAYOFMONTH(MY_DATE) - 1 DAY), 5) + 1 AS WEEK_OF_MONTH,
COUNT(1) AS COUNT,
GROUP_CONCAT(MY_DATE) AS INCLUDE_DATE
FROM (SELECT '2017-01-01' AS MY_DATE
UNION ALL
SELECT '2017-02-08'
UNION ALL
SELECT '2017-02-03'
UNION ALL
SELECT '2017-02-01'
UNION ALL
SELECT '2017-01-21') TMP
GROUP BY WEEK(MY_DATE, 5) - WEEK(DATE_SUB(MY_DATE, INTERVAL DAYOFMONTH(MY_DATE) - 1 DAY), 5) + 1
结果:
mysql取值可为星期一到星期天七天中的某一天的枚举类型很准确。根据查询相关资料信息显示,mysql取值可为星期一到星期天七天中的某一天的枚举类型是weekday枚举,weekday枚举类型常用于各项专业,所以mysql取值可为星期一到星期天七天中的某一天的枚举类型很准确。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)