我有3列作为计数,持续时间和百分比。我对count和duration使用了总计的rollup,但是我想要percentage列的平均值。

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'))

最佳答案

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')))

.....

10-06 10:57