您好,登錄后才能下訂單哦!
With查詢語句已with開頭,相當于在查詢之前先構建一個臨時表,被指定的查詢結果存與臨時表中,之后便可多次使用它做進一步的分析和處理。
語法:
with _tempTable as (select * from table ) select * from _tempTable
例子:
with _tempStudent as( select * from t_student t where class = '初二3班' ) select sex,count(1) nums from _tempStudent where sex = '男' and height > '170' union all select sex,count(1) nums from _tempStudent where sex = '女' and height > '160'
多個with as 用法 每個臨時存量直接用 "," 隔開
with t1 as ( select * from student where name in('張三','李四') ),t2 as ( select * from student where name in('王五') ) select * from t1 union select * from t2
如果with as 有嵌套的情況, 多個with as,后面的as內部可以直接調用先聲明的臨時對象
with t1 as ( select * from student where name in('張三','李四') ),t2 as ( select * from t1 where name in('王五') ) select * from t2
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。