如何从SQL表中获取最后5分钟的记录。如何从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。我想从"Student"
表中获取最后5分钟记录。
例如: 我需要“xyz”用户信息。
我试过下面的查询不工作。
select * from Student where startTime is not null and startTime < GetDate() and startTime > dateadd(minute, -5, GetDate())
但我从学生表中获得空值。
如何做到这一点。请帮我解决。
基于根据你的解释,没有理由你没有记录。 StartTime是什么数据类型?如果你运行'select dateadd(minute,-5,GetDate()),getdate()' –