Middle
What is the purpose of HAVING?
sobes.tech AI
Answer from AI
The HAVING keyword in SQL is used to filter the results of aggregate functions after grouping data with GROUP BY.
While WHERE filters rows before grouping, HAVING filters groups after aggregation.
Example:
SELECT department, COUNT(*) as employee_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 10;
This query will select only those departments that have more than 10 employees.