HAVING Clause
Filters the results of a GROUP BY clause. Semantically, the HAVING clause occurs after the GROUP BY operation. It was added to the SQL standard because a WHERE clause cannot specify aggregate functions.
Syntax
HAVING condition[,…]
Parameters
condition |
Unambiguously references a grouping column, unless the reference appears in an aggregate function. |
Example
The following example returns the employees with salaries greater than $50,000:
=> SELECT employee_last_name, MAX(annual_salary) as "highest_salary" FROM employee_dimension GROUP BY employee_last_name HAVING MAX(annual_salary) > 50000; employee_last_name | highest_salary --------------------+---------------- Bauer | 920149 Brown | 569079 Campbell | 649998 Carcetti | 195175 Dobisz | 840902 Farmer | 804890 Fortin | 481490 Garcia | 811231 Garnett | 963104 Gauthier | 927335 (10 rows)