以下 MySQL 查询按用户获取不同日期的所有周数据:
SELECT user_id,
CONCAT(follow_up_date, ' - ', follow_up_date + INTERVAL 6 day) AS week,
GROUP_CONCAT(follow_up_date)
FROM feedback_2
WHERE follow_up_date > ''
GROUP BY WEEK(follow_up_date),
user_id
输出:
---------------------------------------------------------------
user_id | week | group_concat(follow_up_date)|
---------------------------------------------------------------
4 2012-08-28 - 2012-09-03 | 2012-08-28,2012-08-28,2012-08-29
14 2012-08-28 - 2012-09-03 | 2012-08-28
但我的要求是,如何为同一用户分隔不同的日期。
---------------------------------------------------------------
user_id | week | group_concat(follow_up_date)|
---------------------------------------------------------------
4 2012-08-28 - 2012-09-03 | 2012-08-28,2012-08-28
4 2012-08-28 - 2012-09-03 | 2012-08-29
14 2012-08-28 - 2012-09-03 | 2012-08-28