提取通话记录:
select t1.coll_org_name as 调解组,t1.collector_name as 调解员,
sum(case when t1.callout_type='MANUAL_CALL' then 1 else 0 end ) as '手动拨打量',
sum(case when t1.callout_type='PREDICTIVE_CALL' then 1 else 0 end ) as '预测外呼量',
sum(case when t1.callout_type='MANUAL_CALL' and t1.audio_duration>0 then 1 else 0 end ) as '手动接通量',
sum(case when t1.callout_type='PREDICTIVE_CALL' and t1.audio_duration>0 then 1 else 0 end ) as '预测接通量',
count(t1.callout_type) as '总拨打量',
sum(case when t1.audio_duration>0 then 1 else 0 end ) as '总接通量',
SUBSTR(SEC_TO_TIME(SUM(case when t1.callout_type='MANUAL_CALL' and t1.audio_duration>0 then t1.audio_duration else 0 end)) FROM 1 FOR 9) as '手动通话时长',
SUBSTR(SEC_TO_TIME(SUM(case when t1.callout_type='PREDICTIVE_CALL' and t1.audio_duration>0 then t1.audio_duration else 0 end)) FROM 1 FOR 9) as '预测通话时长',
SUBSTR(SEC_TO_TIME(SUM(t1.audio_duration)) FROM 1 FOR 9) as '总通话时长' #(这个是一个秒转时分秒的函数SUBSTR(SEC_TO_TIME()from 1 for 8-9)也可以用date_format('','%Y%M%D 00:00:00))
from
(select tcr.coll_org_name ,tcr.collector_name ,tcr.callout_type,tcr.duration as audio_duration
from tianrun_callout_record tcr
where tcr.start_time>DATE_FORMAT('2022-11-21','%Y-%m-%d 00:00:00')
and tcr.start_time<=DATE_FORMAT('2022-11-21','%Y-%m-%d 23:59:59')
and tcr.product_type='JZSK' and tcr.collector_name in ('刘欣','刘军','陈连鹤','李明玉','周文龙','王凡','蒲军涛','郑永刚','卫倩','董韶华','范亚慧')
and tcr.coll_org_name not in ('西安内调2-外部')# 多个and条件同时使用
) AS t1
group by t1.coll_org_name,t1.t1.collector_name; # 有sum等聚合函数一定要group