Aggregation condition

Since v0.7.0, HAVING has been added to support the conditional filtering of aggregation results directly. By using HAVING, we can avoid using a subquery after the GROUP BY statement. See the following example:

> SELECT > gender_age.age > FROM employee> GROUP BY gender_age.age > HAVING count(*)=1;+----------------+| gender_age.age |+----------------+| 27             || 30             || 35             || 57             |+----------------+4 rows selected (25.829 seconds)> SELECT > gender_age.age, > count(*) as cnt -- Support use column alias in HAVING, like ORDER BY> FROM employee > GROUP BY gender_age.age HAVING cnt=1; +----------------+-----+| gender_age.age | cnt |+----------------+-----+| 27             | 1   || 30             | 1   || 35             | 1   || 57             | 1   |+----------------+-----+ 4 rows selected ...

Get Apache Hive Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.