使用with语句重用子查询
2017-12-24 22:57
162 查看
--使用子查询
select dname,sum(sal) as dept_total from emp,dept where emp.deptno =dept.deptno group by dname
having sum(sal)>(select sum(sal)*1/3 from emp ,dept where emp.deptno= dept.deptno)
--使用with
with summary as(
select dname,sum(sal) as dept_total from emp,dept where emp.deptno =dept.deptno group by dname
)
select dname,dept_total from summary where dept_total>(select sum(dept_total)*1/3 from summary)
select dname,sum(sal) as dept_total from emp,dept where emp.deptno =dept.deptno group by dname
having sum(sal)>(select sum(sal)*1/3 from emp ,dept where emp.deptno= dept.deptno)
--使用with
with summary as(
select dname,sum(sal) as dept_total from emp,dept where emp.deptno =dept.deptno group by dname
)
select dname,dept_total from summary where dept_total>(select sum(dept_total)*1/3 from summary)
相关文章推荐
- Effective Java 第三版——9. 使用try-with-resources语句替代try-finally语句
- js4:with,for in语句,windows,location对象的使用
- js的with语句使用方法
- JS的with语句的使用方式
- 如何使用with...as...构造SQL语句
- JavaScript中With 语句使用方法实例
- JavaScript中With 语句使用方法实例
- JavaScript with语句使用方法
- 尚未备份数据库 "TEST" 的日志尾部。如果该日志包含您不希望丢失的工作,请使用 BACKUP LOG WITH NORECOVERY 备份该日志。请使用 RESTORE 语句的 WITH REPL
- JavaScript中With 语句使用方法实例
- (转 )Delphi指针如何指向使用with开域语句创建的无名组件对象
- sql with as 语句使用
- js的with语句使用方法
- js的with语句使用方法
- js的with语句使用方法
- Python:with语句的使用
- JavaScript中With 语句使用方法实例
- js的with语句使用方法
- Oracle使用子查询一次性更新或插入多条语句
- 尚未备份数据库 xxxx 的日志尾部。如果该日志包含您不希望丢失的工作,请使用 BACKUP LOG WITH NORECOVERY 备份该日志。请使用 RESTORE 语句的 WITH REPLA