在 SQL 中获取系统日期时间前 10 分钟的记录 [英] Get records 10 min before system datetime in SQL

查看:81
本文介绍了在 SQL 中获取系统日期时间前 10 分钟的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在系统当前日期时间前 10 分钟找到记录.

i need to find the records 10 min before system current datetime.

select Id,TimeStamp from ISAlive where RecordUpdatedDate < GETDATE() --SYSDATETIME()

推荐答案

select Id, TimeStamp
from ISAlive
WHERE RecordUpdatedDate = dateadd(minute,-10,getdate())

可能是一个起点.当然,它可能不会完全匹配...

might be a starting point. Of course, it probably won't match exactly...

...如果您想获得符合该条件的最新记录,请尝试

...if you want to get the most recent record that fits that criteria, however, try

SELECT TOP 1 ID, TimeStamp
FROM ISAlive
WHERE RecordUpdatedDate <= dateadd(minute, -10, getdate())
ORDER BY RecordUpdatedDate DESC

这篇关于在 SQL 中获取系统日期时间前 10 分钟的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆