子查询结果集重复利用

1、MySQL中利用视图可实现对子查询结果集的重复利用:

    drop view if exists ali;
    create view ali as (select * from deal);
   select ali.Volume from ali;
    select ali.`P#` from ali;

2、SQLServer中利用With as可实现对子查询结果集的重复利用;

     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)
 

你可能感兴趣的:(Mysql,mysql)