sql 优化

1.尽量使用列名

2.where 解析顺序 :右==>左

  where  condition1  and condition2  把结果最有可能为false的放在右面

  where condition1 or  and condition2 把结果最有可能为true的放在右面

3.尽量使用where,而不是having 因为 where是先过滤后分组,having是先分组后过滤

  

--查询10号部门的平均工资
SQL> select deptno,avg(sal)
  2  from emp
  3  group by deptno
  4  having deptno=10;
select deptno,avg(sal)
  2  from emp
  3  where deptno=10
  4* group by deptno

 4.尽量使用多表查询,而不是子查询

  因为子查询会查询两次 而多表查询只查询一次,而且oracle也是这样做的,大部分情况下它在优化的时候就把自查询转化为多表查询(分页除外);

 

 

 

 

 

原文地址:https://www.cnblogs.com/jycjy/p/6713328.html