Sobes.tech
Junior — Middle

Do you use the HAVING operator in your SQL queries?

sobes.tech AI

Answer from AI

The HAVING operator is used in SQL to filter groups of data after applying aggregate functions such as COUNT, SUM, AVG, etc. Unlike WHERE, which filters rows before grouping, HAVING filters already grouped data.

Example of usage:

SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 10;

This query will select only those departments with more than 10 employees.

I use HAVING when I need to filter the results of aggregation, for example, when testing reports or checking data with grouping.