Having Clause Aggregate Filter
Filter grouped results with HAVING after aggregation for group-level conditions.
Code
SELECT
department,
COUNT(*) AS employee_count,
AVG(salary) AS avg_salary,
MAX(salary) AS max_salary
FROM employees
WHERE status = 'active'
GROUP BY department
HAVING COUNT(*) > 5 AND AVG(salary) > 50000
ORDER BY avg_salary DESC;Report a problem with this exampleOpens a pre-filled issue on GitHub.