Skip to content

HAVING

SELECT Department, COUNT(Employee) AS Number_Of_Employees
FROM Company
GROUP BY Department
HAVING COUNT(Employee) > 3;
+--------------+-------------------+
| Department | Number_Of_Employees |
+--------------+-------------------+
| Finance | 5 |
| Production | 8 |
+--------------+-------------------+

In this example, the SQL code is grouping the records by department, counting the employees in each department and using the HAVING clause to filter out departments where there are fewer than 3 employees. The output shows the departments where there are more than 3 employees.