WITH AS短語,也叫做子查詢部分(subquery factoring),可以讓你做很多事情,定義一個(gè)SQL片斷,該SQL片斷會(huì)被整個(gè)SQL語句所用到。有的時(shí)候,是為了讓SQL語句的可讀性更高些,也有可能是在UNION ALL的不同部分,作為提供數(shù)據(jù)的部分。
–針對一個(gè)別名
with tmp as (select * from tb_name)
–針對多個(gè)別名
with
tmp as (select * from tb_name),
tmp2 as (select * from tb_name2),
tmp3 as (select * from tb_name3),
…
–相當(dāng)于建了個(gè)e暫時(shí)表
with e as (select * from scott.emp e where e.empno=7499)
select * from e;
–相當(dāng)于建了e、d暫時(shí)表
with
e as (select * from scott.emp),
d as (select * from scott.dept)
select * from e, d where e.deptno = d.deptno;
來源:高三網(wǎng)
能發(fā)現(xiàn)自己知識上的薄弱環(huán)節(jié),在上課前補(bǔ)上這部分的知識,不使它成為聽課時(shí)的“絆腳石”。這樣,就會(huì)順利理解新知識,相信通過with as 用法這篇文章能幫到你,在和好朋友分享的時(shí)候,也歡迎感興趣小伙伴們一起來探討。