HAVING Clause
The HAVING clause filters the results of the GROUP BY clause by using an aggregate function. The HAVING clause uses the same restriction operators as the WHERE clause.
For example, to return parts that have sold more than ten times on a particular day during the past week:
SELECT odate, partno, count(*) FROM orders
GROUP BY odate, partno
WHERE odate >= (CURRENT_DATE – INTERVAL '7' day)
HAVING count(*) > 10;
Any columns or expressions contained in the HAVING clause must follow the same limitations described for the SELECT clause.