我有一個查詢它返回一個確切的時間跨度:SQL - 修改查詢,以便從時間的間隔得到的值,而不是一個固定的時間
SELECT ScanDate FROM tTimes WHERE personId = 5
的值,例如可以:
2016-08-10 16:26:42.000
使用下面的查詢:
SELECT executedTime FROM tTimetable as tc
WHERE tc.lastExecutedTime IN (SELECT ScanDate FROM tTimes WHERE personId =5)
我會得到:
SELECT executedTime FROM tTimetable as tc
WHERE tc.lastExecutedTime IN (2016-08-10 16:26:42.000)
不過,我想從
SELECT executedTime FROM tTimetable as tc
WHERE tc.lastExecutedTime IN (between 2016-08-10 16:16:42.000 and 2016-08-10 16:36:42.000)So everything which is between the `2016-08-10 16:26:42.000-10sec` and `2016-08-10 16:26:42.000+10secs`
獲取值我怎樣才能archieve這樣的結果?
添加一些樣本表數據和預期的結果。 – jarlh
備註:您應該避免[日期和時間類型]的「BETWEEN」和包含上限(http://sqlblog.com/blogs/aaron_bertrand/archive/2011/10/19/what-do-between-and -the-devil-have-in-common.aspx),特別是在SQL Server上。 –