守候你守候我
以周一作为一周的开始, 使用mysql week行数模式5:作为周划分的标准, 比如20170101是周天, week(20170101, 5) = 0,分WEEK_IN_MONTH, 和WEEK_IN_YEAR两种情况进行分组:WEEK_IN_YEAR:12345678910111213# 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:1234567891011121314# 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结果: