一、with as 短語含義
with as短語,也叫做子查詢部分(subquery factoring),可以定義乙個sql片斷,該sql片斷會被整個sql語句用到。可以使sql語句的可讀性更高,也可以在union all的不同部分,作為提供資料的部分。減少巢狀查詢可以提公升sql的查詢效率
二、with as 用法
例如之前的join例項:
select stu_name,grade from
student
join
(select stu_id,grade from course
join
grade
on grade.stu_id=course.stu_id
where couname='語文') as a
on a.stu_id=student.stu_id
也可以通過with as短語實現,如下:
with t1
as select stu_id
,grade
from cource
join
grade
on grade.stu_id=course.stu_id
where couname='語文'
select stu_name
,grade
from t1
join
student
on student.stu_id=t1._stuid
也可以使用多個as,建立多個子查詢部分,如:
with t1
as select id from table_a
,t2 as select id from table_b
,t3 as select id from table_c
selet
t1.id from
t1join
t2on t1.id=t2.id
join
t3on t2.id=t3.id
Sql的with as 的使用
相當於建了個e臨時表 with e as select from scott.emp e where e.empno 7499 select from e 相當於建了e d臨時表 with e as select from scott.emp d as select from scott.dept ...
Sql的with as 的使用
with as 語法 針對乙個別名 with tmp as select from tb name 針對多個別名 with tmp as select from tb name tmp2 as select from tb name2 t as select from tb name3 sql vi...
SQL 中With as 的用法
一 with as的含義 with as短語,也叫做子查詢部分 subquery factoring 可以讓你做很多事情,定義乙個sql片斷,該sql片斷會被整個sql語句所用到。有的時候,是為了讓sql語句的可讀性更高些,也有可能是在union all的不同部分,作為提供資料的部分。特別對於uni...