Example 1
Find departments with more than 3 employees
Finance has 2 employees and is excluded by HAVING COUNT(*) > 3. Only Engineering, with 4 employees, passes the filter.
Source table data Rows loaded before the example query runs.
Setup
CREATE TABLE employees (id INT, name VARCHAR(50), department VARCHAR(50));
INSERT INTO
employees (id, name, department)
VALUES
(1, 'Ada', 'Engineering'),
(2, 'Grace', 'Engineering'),
(3, 'Linus', 'Engineering'),
(4, 'Alan', 'Engineering'),
(5, 'Karen', 'Finance'),
(6, 'Steve', 'Finance');Validated query Shared across supported engines.
SQL
SELECT
department,
COUNT(*) AS headcount
FROM
employees
GROUP BY
department
HAVING
COUNT(*) > 3
ORDER BY
department;Expected result Returned rows for the shared example.
| department | headcount |
|---|---|
| Engineering | 4 |
Output is identical across all engines.