如何從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()' –