按半小时间隔计算呼叫数

时间:2017-06-15 12:10:47

标签: sql sql-server

我试图按半小时间隔计算通话次数。 无法理解。

select 
       count(call_id) as '#Calls',
       1/2 h(date_time) as 'Call_Interval'
from My_Table

enter image description here

1 个答案:

答案 0 :(得分:3)

按不同时间间隔汇总的一种方法是DATEADDDATEDIFF

SELECT 
       COUNT(*) as '#Calls',
       DATEADD(minute, (DATEDIFF(minute, '', date_time) / 30) * 30, '') as Call_Interval
FROM dbo.My_Table
GROUP BY DATEADD(minute, (DATEDIFF(minute, '', date_time) / 30) * 30, '')
ORDER BY Call_Interval;