oracle with as 用法

來源:互聯網
上載者:User

標籤:oracle   with as   查詢結果重複使用   

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


oracle with as 用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.