从15分钟间隔到每小时间隔计数

时间:2014-08-13 07:40:22

标签: sql excel

我正在使用Excel工作表来显示来自sql的数据

SELECT itable.Timestamp, itable.Time,
Sum(itable.CallsOffered)AS CallsOffered, Sum(itable.CallsAnswered)AS CallsAnswered, Sum(itable.CallsAnsweredAftThreshold)AS CallsAnsweredAftThreshold,
sum(CallsAnsweredDelay)AS CallsAnsweredDelay 
FROM tablename itable
WHERE 
(itable.Timestamp>=?) AND (itable.Timestamp<=?) AND 
(itable.Application in ('1','2','3','4'))
GROUP BY itable.Timestamp, itable.Time
ORDER BY itable.Timestamp, itable.Time

我得到的数据间隔为15分钟,如下所示:

Timestamp   Time    CallsOffered    CallsAnswered   CallsAnsweredAftThreshold   CallsAnsweredDelay
6/1/2014 0:00   00:00   0   1   1   52
6/1/2014 0:15   00:15   3   1   1   23
6/1/2014 0:30   00:30   3   3   2   89
6/1/2014 0:45   00:45   0   0   0   0
6/1/2014 1:00   01:00   0   0   0   0
6/1/2014 1:15   01:15   4   1   1   12
6/1/2014 1:30   01:30   1   1   1   39
6/1/2014 1:45   01:45   0   0   0   0
6/1/2014 2:00   02:00   2   1   0   7
6/1/2014 2:15   02:15   1   1   1   80
6/1/2014 2:30   02:30   3   2   2   75
6/1/2014 2:45   02:45   0   0   0   0
6/1/2014 3:00   03:00   0   0   0   0

我希望将间隔从15分钟转换为每小时间隔 像这样

2014-07-01 00:00:00.000
2014-07-01 01:00:00.000
2014-07-01 02:00:00.000
2014-07-01 03:00:00.000
2014-07-01 04:00:00.000
2014-07-01 05:00:00.000
2014-07-01 06:00:00.000
2014-07-01 07:00:00.000
2014-07-01 08:00:00.000
2014-07-01 09:00:00.000
2014-07-01 10:00:00.000
2014-07-01 11:00:00.000
2014-07-01 12:00:00.000
2014-07-01 13:00:00.000
2014-07-01 14:00:00.000

我提出的查询是:

select 
  timestamp = DATEADD(hour,datediff(hour,0,app.Timestamp),0),
  Sum(app.CallsOffered)AS CallsOffered,
  Sum(app.CallsAnswered)AS CallsAnswered,
  Sum(app.CallsAnsweredAftThreshold)AS CallsAnsweredAftThreshold,
  sum(CallsAnsweredDelay)AS CallsAnsweredDelay,
  max(MaxCallsAnsDelay) as MaxCallsAnsDelay , 
  max(app.MaxCallsAbandonedDelay)as MaxCallsAbandonedDelay
from tablename app
where Timestamp >='2014-7-1' AND timestamp<='2014-7-2' and 

(app.Application in (
'1',
'2',
'3',
'4')
group by DATEADD(hour,datediff(hour,0,Timestamp),0)
order by Timestamp;

当我在Microsoft Sql server Managment studio中运行时,我得到了我想要的结果 但是当我尝试在Excel中的Microsoft Query中运行相同的查询时,它给了我一个很长的错误,错误就像我无法从时间戳开始 它给了我DATEADD,DATEDIFF的错误 所以有什么我应该在我的查询或我可以做的任何事情,以获得每小时计数间隔而不是15分钟计数间隔,如我所示 并提前谢谢

0 个答案:

没有答案