Oracle优化查询改写(第三章-操作多个表)
2017-12-03 00:00
387 查看
3.1 UNION ALL 与空字符串(略)
3.2 UNION 与 OR(略)
3.3组合相关的行(略)
3.4 IN,EXISTS和INNER JOIN (略)
3.5 INNER JOIN ,LEFT JOIN 和RIGHT JOIN 和FULL JOIN(略)
3.6 自关联(略)
3.7NOT IN,NOT EXISTS和LEFT JOIN
有些单位的部门中一个员工也没有,只是设了一个部门的名字。
3.8外连接中的条件不要乱放
3.9检测两表中的数据及对应数据条数是否相同
3.10 聚集与内连接
3.11聚集与外连接
3.12从多个表中返回丢失的数据
3.13多表查询时的空值处理
3.2 UNION 与 OR(略)
3.3组合相关的行(略)
3.4 IN,EXISTS和INNER JOIN (略)
3.5 INNER JOIN ,LEFT JOIN 和RIGHT JOIN 和FULL JOIN(略)
drop table L purge; drop table R purge; create table L as select 'left_1' AS str,'1' AS v from dual union all select 'left_2','2' AS v from dual union all select 'left_3','3' AS v from dual union all select 'left_4','4' AS v from dual; create table R AS select 'right_3' AS str,'3' AS v,1 AS status from dual union all select 'right_4' AS str,'4' AS v,0 AS status from dual union all select 'right_5' AS str,'5' AS v,0 AS status from dual union all select 'right_6' AS str,'6' AS v,0 AS status from dual
3.6 自关联(略)
3.7NOT IN,NOT EXISTS和LEFT JOIN
有些单位的部门中一个员工也没有,只是设了一个部门的名字。
select count(*) from emp where deptno=40; COUNT(*) ---------- 0
select * from dept where deptno not in (select emp.deptno from emp where emp.deptno is NOT NULL)
select * from dept where not exists (select null from emp where emp.deptno = dept.deptno)
select dept.* from dept left join emp on emp.deptno = dept.deptno where emp.deptno is null;
3.8外连接中的条件不要乱放
select l.str as left_str,r.str as right_str,r.status from l left join r on (l.v = r.v and r.status=1) order by 1,2;
select l.str as left_str,r.str as right_str,r.status from l left join (select * from r where r.status =1) r on (l.v = r.v) order by 1,2;
3.9检测两表中的数据及对应数据条数是否相同
3.10 聚集与内连接
3.11聚集与外连接
3.12从多个表中返回丢失的数据
3.13多表查询时的空值处理
select a.ename,a.comm from emp a where coalesce(a.comm,0) < (select b.comm from emp b where b.ename='ALLEN') 把NULL值转为0,再比较
相关文章推荐
- 【书评:Oracle查询优化改写】第三章
- 【书评:Oracle查询优化改写】第三章
- 【书评:Oracle查询优化改写】第三章
- 【书评:Oracle查询优化改写】第三章
- ORACLE 优化查询改写(二)
- ORACLE 优化查询改写(一)
- 【书评:Oracle查询优化改写】第二章
- 【书评:Oracle查询优化改写】第五至十三章
- 【书评:Oracle查询优化改写】第14章 结尾章
- oracle 查询优化改写
- 【书评:Oracle查询优化改写】第14章 结尾章
- Oracle优化查询改写(第四章-插入,更新与删除)
- 【书评:Oracle查询优化改写】第14章 结尾章
- oracle 性能优化操作十: 分解复杂查询,用常量代替变量
- Oracle查询优化-03操作多个表
- Oracle优化查询改写(第二章-给查询结果排序)
- oracle 性能优化操作三:增加查询的范围限制
- oracle 查询优化及sql改写
- 【书评:Oracle查询优化改写】第二章
- Oracle优化查询改写(第一章-单表查询)