One - One Code All

Blog Content

SQL子查询结果集重复利用

MySQL PostgreSQL   2019-04-11 21:10:46

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


    drop view if exists ali;

    create view ali as (select * from deal);

    select ali.Volume 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)

 

3、PostgreSQL 中,也是创建视图以重复利用:


CREATE VIEW current_employees AS  

SELECT NAME, ID, SALARY 



上一篇:Aliyun - OSS工具ossutil使用简介
下一篇:mac上python连接SSL报错certificate verify failed: unable to get local issuer certificate _ssl.c:1123

The minute you think of giving up, think of the reason why you held on so long.