使用with语句重用子查询

2023-05-16

 --使用子查询
 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)
 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用with语句重用子查询 的相关文章

随机推荐