如何从SQL表中获取最近5分钟的记录。
例如:我有一个表名叫做Student。
ID Name StartTime
-- ---------- ----------------------
1 abc 2016-05-18 08:00:29.587
2 xxx 2016-05-18 08:05:30.287
3 xyz 2016-05-18 08:10:30.287
现在考虑时间是上午8:15。我想从表中获取最后5分钟的记录"Student"
。
例如:我需要“ xyz”用户信息。
我尝试了以下查询无法正常工作。
select * from Student where startTime is not null and startTime < GetDate() and startTime > dateadd(minute, -5, GetDate())
但是我从学生表中获取空值。
怎么做。请帮我解决。
select * from Student where startTime is not null and startTime > DATEADD(minute, -5, GETUTCDATE())
试试这个代码
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句