我需要在系统当前日期时间前10分钟找到记录。
select Id,TimeStamp from ISAlive where RecordUpdatedDate < GETDATE() --SYSDATETIME()
答案 0 :(得分:29)
select Id, TimeStamp
from ISAlive
WHERE RecordUpdatedDate = dateadd(minute,-10,getdate())
可能是一个起点。当然,它可能不会完全匹配...
...如果您想获得符合该标准的最新记录,请尝试
SELECT TOP 1 ID, TimeStamp
FROM ISAlive
WHERE RecordUpdatedDate <= dateadd(minute, -10, getdate())
ORDER BY RecordUpdatedDate DESC
答案 1 :(得分:4)
SELECT Id, TimeStamp
FROM ISAlive
WHERE RecordUpdatedDate < DATEADD(minute,-10, SYSDATETIME());
答案 2 :(得分:1)
NOW() + INTERVAL 2 MINUTE
NOW() + INTERVAL 5 MINUTE
NOW() + INTERVAL 10 MINUTE
答案 3 :(得分:0)
您可以使用now()完成此操作
SELECT Id, TimeStamp
FROM ISAlive
WHERE RecordUpdatedDate <= NOW() - INTERVAL 10 MINUTE;