3

我通过 mysql NOW() 函数在“日期”字段中记录了数据。我想选择记录最近三天(今天、昨天和前天)的数据,但不知道要这样做。

SELECT * FROM tlb_students WHERE date ...?... ORDER BY date DESC LIMIT 20
4

4 回答 4

4
WHERE date >= ( CURDATE() - INTERVAL 3 DAY )
于 2012-07-09T02:53:43.813 回答
4
SELECT * 
FROM tlb_students 
WHERE date >= NOW() - INTERVAL 3 DAY
ORDER BY date DESC
LIMIT 20
于 2012-07-09T02:56:53.403 回答
2
WHERE date >= subdate(NOW(), 2) 
于 2012-07-09T03:04:08.593 回答
1

另一种方法是:

SELECT * FROM tlb_students WHERE date < DATE_ADD(CURDATE(),INTERVAL -3 DAY)
于 2012-07-09T03:01:58.157 回答