Purpose: The HAVING
clause filters results after aggregation, allowing you to specify conditions on grouped records.Syntax
HAVING condition;
Example:
SELECT department_id, AVG(salary) AS avg_salary FROM employees GROUP BY department_id HAVING AVG(salary) > 50000;
Explanation: This retrieves departments where the average salary exceeds 50,000. HAVING
is used because the condition is applied after grouping.
Leave a Reply