我有一个时间戳列,可以在插入/更新时自动更新。
我想获取最近10分钟内已更新的行。
SELECT * FROM status WHERE code='myCode' AND 'stamp_updated' BETWEEN NOW() AND DATE_ADD(NOW() , INTERVAL - 10 MINUTE) ORDER BY stamp_updated DESC LIMIT 1
使用:
SELECT * FROM status WHERE code = 'myCode' AND `stamp_updated` BETWEEN DATE_SUB(NOW() , INTERVAL 10 MINUTE) AND NOW() ORDER BY stamp_updated DESC LIMIT 1
BETWEEN运算符中的顺序很重要-您倒退了。