2014-07-24 137 views
0

我需要計算一些範圍內的記錄,但從長期來看,例如: 我採取範圍'2014-07-01'和'2014 -07-21',但我只需要21:00:00和21:30:00之間的記錄...如何在t-sql的時間範圍內採取更長的時間範圍

Count(records) between '2014-07-01 21:00:00' and '2014-07-01 21:30:00' 
Count(records) between '2014-07-02 21:00:00' and '2014-07-02 21:30:00' 
... 

謝謝!

回答

2

你可以試試這樣:

SELECT COUNT(records) 
FROM [yourtable] 
WHERE [timestamp] BETWEEN '2014-07-01' AND '2014-07-02' 
    AND CONVERT(TIME, [timestamp]) BETWEEN '21:00:00' AND '21:30:00'