Impala - 不同運算元



Impala 中的distinct 運算元用於透過刪除重複項來獲取唯一值。

語法

以下是distinct 運算元的語法。

select distinct columns… from table_name;

示例

假設我們在 Impala 中有一個名為customers 的表,其內容如下 -

[quickstart.cloudera:21000] > select distinct id, name, age, salary from customers; 
Query: select distinct id, name, age, salary from customers

在這裡,你可以看到 Rames 和 Chaitali 的薪資輸入了兩次,並且可以使用distinct 運算元選擇唯一值,如下所示。

[quickstart.cloudera:21000] > select distinct name, age, address from customers;

在執行時,上述查詢給出以下輸出。

Query: select distinct id, name from customers
+----------+-----+-----------+ 
| name     | age | address   | 
+----------+-----+-----------+ 
| Ramesh   | 32  | Ahmedabad |
| Khilan   | 25  | Delhi     | 
| kaushik  | 23  | Kota      | 
| Chaitali | 25  | Mumbai    |
| Hardik   | 27  | Bhopal    |
| Komal    | 22  | MP        | 
+----------+-----+-----------+
Fetched 9 row(s) in 1.46s
廣告