- Categories:
HAVING¶
Filters rows produced by GROUP BY that do not satisfy a predicate.
Syntax¶
SELECT ...
FROM ...
GROUP BY ...
HAVING <predicate>
[ ... ]
Parameters¶
predicate
A boolean expression.
Usage notes¶
The condition specified by the HAVING clause applies to expressions produced by the GROUP BY. Therefore, the same restrictions that apply to GROUP BY expressions also apply to the HAVING clause. The predicate can only refer to:
Constants.
Expressions that appear in GROUP BY.
Expressions in the SELECT list can be referred to by the column alias defined in the list.
Examples¶
Find the departments that have fewer than 10 employees:
SELECT department_id FROM employees GROUP BY department_id HAVING count(*) < 10;