我有这个查询,从我的表中选择最近4周的记录:
SELECT * FROM activity
WHERE dateAdded
BETWEEN date_sub(now(),INTERVAL 4 WEEK) AND now()
ORDER BY activity ASC;
但是我想从4周前的星期一开始选择最近4周的记录,无论当天如何。
此外,查询似乎没有选择今天的记录。
答案 0 :(得分:0)
试试这个:SELECT * FROM activity
WHERE dateAdded
BETWEEN date_sub(date_sub(now(), INTERVAL 4 DAY),INTERVAL 4 WEEK) AND date_sub(now(), INTERVAL 4 DAY)
ORDER BY activity ASC;
答案 1 :(得分:0)
完成了工作。
SELECT * FROM activity
WHERE
YEARWEEK(`dateAdded`, 1) = YEARWEEK(DATE_SUB(curdate(), INTERVAL 3 WEEK), 1)
ORDER BY activity ASC;