HAVING
clause
Examples
-
Let’s count the number of records in the
employees
table that contain each of the different departments, discarding departments with less than 10:SELECT department, count(*) FROM employees GROUP BY department HAVING count(*) >= 10;
-
Calculate the average salary for each department of each division , but only for those departments where the average salary is greater than the median salary:
SELECT division, department, avg(salary) FROM employees GROUP BY division, department HAVING avg(salary) > median(salary);