0

我想要上周的所有数据。我用了

SELECT id FROM tbl
WHERE date >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND date < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY 

但是当我的一周从“星期一”开始时它不起作用。

我应该怎么办?

4

3 回答 3

0
SELECT id FROM tbl WHERE date  >= CURDATE() - INTERVAL (WEEKDAY(CURDATE())+7) DAY  AND date   <  CURDATE()  - INTERVAL (WEEKDAY(CURDATE())) DAY 

我试试这个,它对我有用。

于 2012-09-19T13:40:03.820 回答
0

然后像这样改变

$lastweek = unix_to_human(time("Y-m-d H:i:s") - (7 * 24 * 60 * 60), TRUE, 'us');
SELECT id FROM tbl
WHERE date >= curdate() - $lastweek
AND date < curdate() - $lastweek 
于 2012-09-19T11:45:08.560 回答
0

尝试

SELECT id FROM tbl
WHERE YEARweek(date) = YEARweek(curdate())
于 2012-09-19T11:46:14.160 回答