您的位置:首页 > 数据库 > Oracle

Oracle with重用子查询

2017-02-06 19:50 162 查看
--with 重用子查询
对于多次使用相同子查询的复杂查询语句来说,用户可能会将查询语句分成两条语句执行。第一条语句将子查询结果存放到临时表,第二条查询语句使用临时表处理数据。从 Oracle 9i 开始,通过 with 子句可以给予子查询指定一个名称,并且使得在一条语句中可以完成所有任务,从而避免了使用临时表。

SCOTT@ test10g> with summary as (
2 select dname, sum(sal) dept_total from emp, dept
3 where emp.deptno=dept.deptno group by dname
4 )
5 select dname,dept_total from summary
6 where dept_total>
7 (select sum(dept_total)*1/3 from summary);

DNAME DEPT_TOTAL
-------------- ----------
RESEARCH 10875
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: