如何按SQL Server的日期时间选择最新记录?
这是伪代码…
SELECT Records FROM MyTable WHERE current time >= (CurrentTime - 2 minutes)
假设当前时间是10:25:39 pm
26/10/2009 10:25:39 pm 26/10/2009 10:25:00 pm 26/10/2009 10:24:53 pm 26/10/2009 10:24:19 pm 26/10/2009 10:23:58 pm 26/10/2009 10:14:56 pm 26/10/2009 10:12:56 pm
SQL查询应返回这些记录…
26/10/2009 10:25:39 pm 26/10/2009 10:25:00 pm 26/10/2009 10:24:53 pm 26/10/2009 10:24:19 pm
实码:
SELECT * FROM MyTable WHERE currentTime >= DATEADD(n, -2, GETDATE()) ORDER BY currentTime DESC