首页 > 代码库 > 脑残的sql
脑残的sql
原sql 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), 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 (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), 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 < to_date(‘2014-09-01 00:00:00‘, ‘YYYY-MM-DD HH24:MI:SS‘)
本文出自 “专注于Oracle性能调优” 博客,谢绝转载!
脑残的sql
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。