
- 特定於資料庫的語句
- Impala - 建立資料庫
- Impala - 刪除資料庫
- Impala - 選擇資料庫
- 特定於表的語句
- Impala - Create Table 語句
- Impala - Insert 語句
- Impala - Select 語句
- Impala - Describe 語句
- Impala - Alter Table
- Impala - 刪除表
- Impala - 截斷表
- Impala - 顯示錶
- Impala - 建立檢視
- Impala - 更改檢視
- Impala - 刪除檢視
- Impala - 子句
- Impala - Order By 子句
- Impala - Group By 子句
- Impala - Having 子句
- Impala - Limit 子句
- Impala - Offset 子句
- Impala - Union 子句
- Impala - With 子句
- Impala - Distinct 運算子
- Impala 有用資源
- Impala - 快速指南
- Impala - 有用資源
- Impala - 討論
Impala - With 子句
如果查詢過於複雜,我們可以定義複雜部分的別名,並使用 Impala 的with 子句將它們包含在查詢中。
語法
以下是 Impala 中with 子句的語法。
with x as (select 1), y as (select 2) (select * from x union y);
示例
假設我們在資料庫my_db 中有一個名為customers 的表,其內容如下 −
[quickstart.cloudera:21000] > select * from customers; Query: select * from customers +----+----------+-----+-----------+--------+ | id | name | age | address | salary | +----+----------+-----+-----------+--------+ | 1 | Ramesh | 32 | Ahmedabad | 20000 | | 9 | robert | 23 | banglore | 28000 | | 2 | Khilan | 25 | Delhi | 15000 | | 4 | Chaitali | 25 | Mumbai | 35000 | | 7 | ram | 25 | chennai | 23000 | | 6 | Komal | 22 | MP | 32000 | | 8 | ram | 22 | vizag | 31000 | | 5 | Hardik | 27 | Bhopal | 40000 | | 3 | kaushik | 23 | Kota | 30000 | +----+----------+-----+-----------+--------+ Fetched 9 row(s) in 0.59s
以相同方式,假設我們有另一張名為employee 的表,其內容如下 −
[quickstart.cloudera:21000] > select * from employee; Query: select * from employee +----+---------+-----+---------+--------+ | id | name | age | address | salary | +----+---------+-----+---------+--------+ | 3 | mahesh | 54 | Chennai | 55000 | | 2 | ramesh | 44 | Chennai | 50000 | | 4 | Rupesh | 64 | Delhi | 60000 | | 1 | subhash | 34 | Delhi | 40000 | +----+---------+-----+---------+--------+ Fetched 4 row(s) in 0.59s
以下是 Impala 中with 子句的示例。在此示例中,我們使用with 子句顯示了employee 和customers 中年齡大於 25 的記錄。
[quickstart.cloudera:21000] > with t1 as (select * from customers where age>25), t2 as (select * from employee where age>25) (select * from t1 union select * from t2);
執行後,上述查詢將產生以下輸出。
Query: with t1 as (select * from customers where age>25), t2 as (select * from employee where age>25) (select * from t1 union select * from t2) +----+---------+-----+-----------+--------+ | id | name | age | address | salary | +----+---------+-----+-----------+--------+ | 3 | mahesh | 54 | Chennai | 55000 | | 1 | subhash | 34 | Delhi | 40000 | | 2 | ramesh | 44 | Chennai | 50000 | | 5 | Hardik | 27 | Bhopal | 40000 | | 4 | Rupesh | 64 | Delhi | 60000 | | 1 | Ramesh | 32 | Ahmedabad | 20000 | +----+---------+-----+-----------+--------+ Fetched 6 row(s) in 1.73s
廣告