SQL AVG查询需要帮助

时间:2014-09-02 14:47:09

标签: sql database

我的问题是我试图找到通话的平均时间长度。

所以继承我的专栏, "     ID已打开联系人类别子类别原因说明TakenBy AssignedTo已关闭 " 所以我希望我的查询在这些结果上添加一个额外的列,显示在关闭之前打开呼叫的平均时间,由开放日期和结束日期之间的时间计算。

我的查询如下所示:

Select  ID, Opened, Contact, Category, SubCategory, Cause, Description, TakenBy, AssignedTo, Closed
From TCall
where CustID = 163
and Opened between '2013-09-01 00:00:00.000' and '2014-09-01 00:00:00.000'

需要更多信息,请问我。

1 个答案:

答案 0 :(得分:0)

你可以这样做:(假设ms sql)

select  avg(secondDuration)
from (
    Select  ID, Opened, Contact, Category, SubCategory, Cause, Description, TakenBy, AssignedTo, Closed, dateDiff(s, opened, closed) as secondDuration
    From TCall
    where CustID = 163
    and Opened between '2013-09-01 00:00:00.000' and '2014-09-01 00:00:00.000'
) subQuery