我有包含秒[時間]值的數據。我想根據每秒多少條記錄來計數我的數據。組間隔時間間隔爲5秒
這是這樣的:
SELECT [Time], count(*)
FROM [dbo].[Times]
GROUP BY
[Time] ORDER By [Time]
這給了我:
+----------+----+
| 00:00:00 | 4 |
+----------+----+
| 00:00:01 | 2 |
+----------+----+
| 00:00:02 | 1 |
+----------+----+
| 00:00:08 | 2 |
+----------+----+
...
我想組,並在5秒間隔數得過來,所以結果看起來像:
+----------+----+
| 00:00:05 | 7 | <-- # of records between 0:00:00 and 0:00:05
+----------+----+
| 00:00:10 | 2 | <-- # of records between 0:00:05 and 0:00:10
+----------+----+
...
任何好的方法你在MS SQL中做到這一點?
查看內聯函數以縮短時間。看到這個:http://stackoverflow.com/questions/249794/how-to-round-a-time-in-t-sql – Parfait
'SELECT Cast(Dateadd(SECOND,(Datediff(SECOND,0,[time])/5 + 1)* 5,0)AS TIME)AS [秒], COUNT(*) FROM [DBO]。[次] GROUP BY DATEADD(SECOND,(DATEDIFF(SECOND,0,[時間])/5 + 1)* 5,0); ' –