- Query Syntax
Filters rows produced by GROUP BY that do not satisfy a predicate.
SELECT ... FROM ... GROUP BY ... HAVING <predicate> [ ... ]
- A boolean expression.
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:
Expressions in the SELECT list can be referred to by the column alias defined in the list.
Find the departments that have fewer than 10 employees:
SELECT department_id FROM employees GROUP BY department_id HAVING count(*) < 10;