Original Sqlselect coalesce (SUM (Telecom_count), 0) AS telecom_count, coalesce (SUM (Telecom_money), 0) AS telecom_money, coalesce (SUM (Mobile_count), 0) AS mobile_count, coalesce (SUM (Mobile_money), 0) AS mobile_money, COALESCE (SUM (Unicom_count), 0) AS unicom_count, COALESCE (SUM (Unicom_money), 0) AS unicom_money, COALESCE (SUM (Fixandphs_count), 0) AS fixandphs_count, COALESCE (SUM (Fixandphs_money), 0) AS fixandphs_money, COALESCE (SUM (recharge_num), 0) AS recharge_num, COALESCE (SUM (Recharge_money), &NBsp;0) AS recharge_money FROM (select a.agent_id, coalesce (SUM (A.telecom_count), 0) as telecom_count, coalesce (SUM (A.telecom_money), 0) AS telecom_money, coalesce (SUM (A.mobile_count), 0) AS mobile_count, COALESCE (SUM (A.mobile_money), 0) AS mobile_money, coalesce (SUM (A.unicom_count), 0) AS unicom_ Count, coalesce (SUM ( A.unicom_money, 0) AS unicom_money, COALESCE (SUM (A.fixandphs_count), 0) AS fixandphs_count, coalesce (SUM (A.fixandphs_money), 0) AS fixandphs_money, COALESCE (SUM (a.recharge_num), 0) AS recharge_num, coalesce (SUM (A.recharge_money), 0) AS recharge_ money from tb_agent_charge_count a LEFT JOIN tb_agent b ON a.agent_id = b.id whEre a.agent_id != -10010 and a.create_date >= to_date (' 2014-08-01 00:00:00 ', ' yyyy-mm-dd hh24:mi:ss ') AND a.create_date < to_date (' 2014-09-01 00:00:00 ', ' YYYY-MM-DD hh24:mi:ss ') group by a.agent_id) Select coalesce (SUM (Telecom_count), 0) AS telecom_count, coalesce (SUM (Telecom_money), 0) AS telecom_money, coalesce (SUM (Mobile_count), 0) AS mobile_count, COALESCE (SUM (Mobile_money), &NBsp;0) as mobile_money, coalesce (SUM (Unicom_count), 0) as unicom_count, coalesce (SUM (Unicom_money), 0) As unicom_money, coalesce (SUM (Fixandphs_count), 0) AS fixandphs_count, coalesce (SUM (Fixandphs_money), 0) AS fixandphs_money, coalesce (SUM (recharge_num), 0) AS recharge_num, coalesce (SUM (Recharge_money), 0) AS recharge_money from tb_agent_charge_count a where a.agent_id != -10010 and a.create_date >= to_ Date (' 2014-08-01 00:00:00 ', ' yyyy-mm-dd hh24:mi:ss ') and a.create_date < &Nbsp; to_date (' 2014-09-01 00:00:00 ', ' yyyy-mm-dd hh24:mi:ss ')
This article is from "Focus on Oracle Performance Tuning" blog, declined reprint!
Brain-Crippled SQL