select count(extension_num) as callAll,sum(talk_length) as talkLength,
count(case when call_type=1 then 1 else null end) as callin,
count(case when call_type=0 then 1 else null end) as callout,
COUNT(case when call_type=0 and talk_length>0 then 1 else null end) as calloutYes,
COUNT(case when call_type=0 and talk_length=0 then 1 else null end) as calloutNo,
COUNT(case when call_type=1 and talk_length=0 then 1 else null end) as callinNo,
COUNT(case when call_type=1 and talk_length>0 then 1 else null end) as callInYes,
extension_num from t_call_call_record GROUP BY extension_num
select *,CONCAT((calloutYes/callout*100),'%') calloutPer,CONCAT((callinYes/callin*100),'%') callinper from (
select count(extension_num) as callAll,sum(talk_length) as talkLength,
count(case when call_type=1 then 1 else null end) as ca