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
在这里您可以观察客户Ramesh和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
转载本站内容时,请务必注明来自W3xue,违者必究。