sql简单优化点滴
2014-10-24 11:32
232 查看
select uppagent.agent_no AGENT_NO, ISNULL(countsubagent,0) REFERRAL_AGENT_NUM, ISNULL(countsubcustomer,0) CUSTOMER_NUM
from AGENT_CORRELATION uppagent
LEFT JOIN (select UPPER_AGENT_NO AGENT,count(AGENT_NO) countsubagent from AGENT_CORRELATION where UPPER_AGENT_NO is not NULL group by UPPER_AGENT_NO) subagent
on uppagent.AGENT_NO=subagent.AGENT
LEFT JOIN (select UPPER_AGENT_NO,count(id) countsubcustomer from CUSTOMER_INFO where UPPER_AGENT_NO is not NULL group by UPPER_AGENT_NO) customer
on customer.UPPER_AGENT_NO=uppagent.AGENT_NO
这种效率会高点
1,通过where UPPER_AGENT_NO is not NULL等条件使得大表转为小表
2. 使用单表统计后的数据进行关联效率比多表关联后的数据进行统计效率要高
from AGENT_CORRELATION uppagent
LEFT JOIN (select UPPER_AGENT_NO AGENT,count(AGENT_NO) countsubagent from AGENT_CORRELATION where UPPER_AGENT_NO is not NULL group by UPPER_AGENT_NO) subagent
on uppagent.AGENT_NO=subagent.AGENT
LEFT JOIN (select UPPER_AGENT_NO,count(id) countsubcustomer from CUSTOMER_INFO where UPPER_AGENT_NO is not NULL group by UPPER_AGENT_NO) customer
on customer.UPPER_AGENT_NO=uppagent.AGENT_NO
这种效率会高点
1,通过where UPPER_AGENT_NO is not NULL等条件使得大表转为小表
2. 使用单表统计后的数据进行关联效率比多表关联后的数据进行统计效率要高
相关文章推荐
- MySQL中SQL优化和架构设计的一些简单想法
- [原创]MySQL中SQL优化和架构设计的一些简单想法
- SQL点滴22—性能优化没有那么神秘
- SQL点滴28—一个简单的存储过程
- 一次简单的SQL优化给我的经验--索引不可用的情况
- [原创]MySQL中SQL优化和架构设计的一些简单想法
- 简单说下SQL优化
- SQL点滴22—性能优化没有那么神秘
- SQL点滴22—性能优化没有那么神秘
- sql简单的性能优化
- [原创]MySQL中SQL优化和架构设计的一些简单想法
- SQL点滴3—一个简单的字符串分割函数
- Oracle sql语句简单优化
- SQL点滴22—性能优化没有那么神秘
- Oracle sql语句简单优化
- MySQL中SQL优化和架构设计的一些简单想法
- 【转】MySQL中SQL优化和架构设计的一些简单想法
- sql优化点点滴
- SQL点滴22—性能优化没有那么神秘
- Sql语句的简单优化