SQL查询返回双重结果

时间:2013-10-01 06:30:07

标签: sql sql-server-2008 sum

早上好,

以下代码返回的数字恰好是我们的数据源对日期&有问题的工人组。我在这里做错了什么?


USE CMT
GO

DECLARE @rd int

SET @rd='41426'

SELECT [date]
  ,skillGroup 
  ,interval/48.000 interval
  ,sum(callsoffered)callsoffered
  ,sum(handleTime) /CAST(NULLIF(sum(acdcalls),0) as decimal(6,0))CRT
  ,(sum(acceptable) /cast(NULLIF(sum(callsoffered),0) as decimal(6,0))) SL   
FROM vwForGrpISplit
WHERE [date] IN(@rd)
AND skillGroup IN ('AC English','AC Spanish','Consumer Credit','WLNP','CC Gen','CC 
Spanish','Retention','Spanish Retention','Device Gen','RSL','FC Gen','FC   Spanish','HBRM English','HBRM Spanish','Technical Care','STC','Tech Care Spanish','Prepaid English','Prepaid Spanish','Sub prime Tech')
GROUP BY [date], skillGroup, interval
ORDER BY skillGroup,[date], interval

代码运行时没有错误,但为查询的这一部分引用的指标返回了错误的值:

下,总和(callsoffered)callsoffered

应该得到27的结果,但是我得到54.对于公式的这部分拉出的所有其他数据也是如此。

这两个公式都提取了正确的值:

  ,sum(handleTime) /CAST(NULLIF(sum(acdcalls),0) as decimal(6,0))CRT

  ,(sum(acceptable) /cast(NULLIF(sum(callsoffered),0) as decimal(6,0))) SL 

我确信这很简单。有人可以帮帮我吗?

由于

0 个答案:

没有答案