如何在汇总中将平均列与总数相加?

时间:2018-06-27 12:18:13

标签: sql postgresql group-by

我有3种计数,持续时间和百分比。我使用汇总来计算总数和持续时间,但我希望获得百分比列的平均值。

select to_char(anstime,'HH24'),
       count(anstime),
       sum(billdurtn),
       round((sum(billdurtn)/(30*3600*1))*100,2) 
from crm.t_ivr_detailed_logs 
where date(anstime)='2018-06-22' 
group by rollup(to_char(anstime,'HH24'))

1 个答案:

答案 0 :(得分:2)

替换您的round((sum(billdurtn)/(30*3600*1))*100,2)
avg(SELECT round((sum(billdurtn)/(30*3600*1))*100,2)
FROM crm.t_ivr_detailed_logs 
where date(anstime)='2018-06-22'
group by rollup(to_char(anstime,'HH24')))

.....