我试图按半小时间隔计算通话次数。 无法理解。
select
count(call_id) as '#Calls',
1/2 h(date_time) as 'Call_Interval'
from My_Table
答案 0 :(得分:3)
按不同时间间隔汇总的一种方法是DATEADD
和DATEDIFF
:
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;