我(为了简单起见)调整了一个包含2列的表 - start
和end
,这两列都是时间戳。这些代表电话。
我需要产生一些归结为图形,沿X轴的时间,以及沿Y轴的同时调用。
我可以很容易地在任何给定时间提取并发呼叫的数量 - 当然是这样的:
select
count(*)
from
calls_table
where
time_started < 1282854000 and time_ended > 1282854000
这只是给了我特定时间的数字。我需要做的是在我的查询中包括选择的时间(例如每小时一小时)并拉出该时间戳的同时呼叫计数?感谢所有伟大的想法!
答案 0 :(得分:2)
如果是SQL Server 2005+,您可以使用随后加入的递归CTE。示例如下。
declare @start int
declare @end int
declare @increment int
set @start = 1282854000
set @increment = 10000
set @end = 1282954000
;with nums as
(
select @start as i
UNION ALL
select i+@increment
FROM nums
where i+@increment <= @end
)
select i
from nums
option (maxrecursion 0)
答案 1 :(得分:-1)
有几种可能的方法,一些可以想到: