hive 之with....as的用法


1.作用

  with 。。as需要定義一個sql片段,會將這個片段產生的結果集保存在內存中,后續的sql均可以訪問這個結果集,作用與視圖或臨時表類似.

2語法

  1. with...as...必須和其他sql一起使用(可以定義一個with但在后續語句中不使用他)
  2. with...as...是一次性的,是臨時的

3.用法

    1.可以單獨使用

-- with table_name as(子查詢語句) 其他sql 
with temp as (
    select * from xxx
)
select * from temp;

  2.嵌套連續使用

with temp2 as (
    with temp1 as (
        select * from xxx
    )
    select * from temp1
)
select * from temp2;

  3.可以當 join…on 使用

with temp1 as (
    select * from xxx
),temp2 as (
    select * from xxx
)
select * from temp1,temp2;

  一般來說:
  表少用join…on
  表多用with…as


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM