开发手册 欢迎您!
软件开发者资料库

Impala - Having Clause

Impala有条款 - 从概述,环境,架构,外壳,查询语言基础,创建数据库,删除数据库,选择数据库,创建表语句,插入语句,选择语句,描述语句,更改表,删除,了解Impala表,截断表,显示表,创建视图,更改视图,删除视图,按条件排序,按条款分组,有条款,限制条款,抵消条款,联盟条款,条款,不同运营商。

Impala中的拥有子句使您可以指定过滤哪些组结果出现在最终结果中的条件.

通常,拥有子句与 group by 子句一起使用;它将条件放在GROUP BY子句创建的组上.

语法

以下是子句的语法.

select * from table_name ORDER BY col_name [ASC|DESC] [NULLS FIRST|NULLS LAST]

示例

假设我们在数据库 my_db 中有一个名为 customers 的表,其内容为如下 :

[quickstart.cloudera:21000] > select * from customers; Query: select * from customers +----+----------+-----+-------------+--------+ | id | name     | age | address     | salary | +----+----------+-----+-------------+--------+ | 1  | Ramesh   | 32  | Ahmedabad   | 20000  || 2  | Khilan   | 25  | Delhi       | 15000  | | 3  | kaushik  | 23  | Kota        | 30000  | | 4  | Chaitali | 25  | Mumbai      | 35000  | | 5  | Hardik   | 27  | Bhopal      | 40000  | | 6  | Komal    | 22  | MP          | 32000  | | 7  | ram      | 25  | chennai     | 23000  | | 8  | rahim    | 22  | vizag       | 31000  | | 9  | robert   | 23  | banglore    | 28000  | +----+----------+-----+-----------+--------+ Fetched 9 row(s) in 0.51s

以下是在Impala : 中使用拥有子句的示例;

[quickstart.cloudera:21000] > select max(salary) from customers group by age having max(salary) > 20000;

此查询最初按年龄对表格进行分组,并选择每个组的最高工资,并显示大于20000的工资,如下所示.

20000 +-------------+ | max(salary) |+-------------+ | 30000       || 35000       | | 40000       | | 32000       | +-------------+ Fetched 4 row(s) in 1.30s