我通过 mysql NOW() 函数在“日期”字段中记录了数据。我想选择记录最近三天(今天、昨天和前天)的数据,但不知道要这样做。
SELECT * FROM tlb_students WHERE date ...?... ORDER BY date DESC LIMIT 20
WHERE date >= ( CURDATE() - INTERVAL 3 DAY )
SELECT *
FROM tlb_students
WHERE date >= NOW() - INTERVAL 3 DAY
ORDER BY date DESC
LIMIT 20
WHERE date >= subdate(NOW(), 2)
另一种方法是:
SELECT * FROM tlb_students WHERE date < DATE_ADD(CURDATE(),INTERVAL -3 DAY)