这是我用来返回过去24小时记录的代码
SELECT *
FROM mytable
WHERE CASE WHEN `created` > DATE_SUB(NOW(), INTERVAL 1 DAY) THEN 1 ELSE 0 END
如何在昨天和过去7天之间返回记录
答案 0 :(得分:0)
使用BETWEEN
运算符。
CASE WHEN created BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND DATE_SUB(NOW(), INTERVAL 1 DAY)
THEN 1
ELSE 0
END
答案 1 :(得分:0)
试试这个,它没有case语句,所以应该更快:
SELECT *
FROM mytable
WHERE created BETWEEN date(CURRENT_TIMESTAMP-7) AND date(CURRENT_TIMESTAMP-1);