您的位置:首页 > 其它

使用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)

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