现在正在工作..您必须查询查询所有结果查询。
SELECT Extn, COUNT(*) as Total_Calls, SEC_TO_TIME(SUM(cldp_talk_time/1000)) as Talk_Time, SUM(cost/100000) as 'Total_Cost' from(
select clngp_digits as Extn, cldp_talk_time, cost from cr20140130 where record_type = 'D' or record_type = 'C'
union all
select cldp_digits as Extn, cldp_talk_time, cost from cr20140130 where record_type = 'D' or record_type = 'B'
union all
select clngp_digits as Extn, cldp_talk_time, cost from cr20140131 where record_type = 'D' or record_type = 'C'
union all
select cldp_digits as Extn, cldp_talk_time, cost from cr20140131 where record_type = 'D' or record_type = 'B'
) t group by Extn order by Extn ASC