平均通话时间列SQL

时间:2015-03-12 12:34:01

标签: sql-server sql-server-2008

我需要专家的帮助,因为我要把头发拉出来。我有一份报告,显示了他们描述的记录数。我试图在平均通话时间和总数之间添加,但这不起作用(它给每一行)可以有人帮忙吗?如何将秒转换为HH:MM:SS

SELECT 
   CONVERT(varchar(12), dbo.cmp_SimplifyDigital.CallDate, 110) AS CallDate, 
   dbo.CRC.Description, COUNT(dbo.CRC.Description) AS Volume, 
   AVG(DISTINCT dbo.History.TalkTime) AS AVGTalk
FROM 
   dbo.cmp_SimplifyDigital
INNER JOIN 
   dbo.Dial ON dbo.cmp_SimplifyDigital.DialID = dbo.Dial.DialID
INNER JOIN 
   dbo.CRC ON dbo.Dial.CRC = dbo.CRC.CRC
LEFT OUTER JOIN 
   dbo.History ON dbo.Dial.HistoryID = dbo.History.HistoryID
WHERE 
   (dbo.cmp_SimplifyDigital.CallDate = CONVERT(varchar(12), GETDATE(), 110))
GROUP BY 
   dbo.cmp_SimplifyDigital.CallDate, dbo.CRC.Description, 
   dbo.History.TalkTime

1 个答案:

答案 0 :(得分:1)

您无法获取TalkTime的平均值,因为它包含在您的group by子句中。拿出来,你将获得dbo.cmp_SimplifyDigital.CallDate,dbo.CRC.Description

的平均TalkTime。