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