Ravi Sir's Cyber Security Cards › Revision Cards
Aggregate Functions, GROUP BY and HAVING
Aggregate Functions, GROUP BY and HAVING Aggregate functions sum up many rows: COUNT, SUM, AVG, MIN, MAX. GROUP BY makes groups. HAVING filters groups. FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT. WHERE COUNT(*) > 1 gives an error. WHERE runs before grouping. Use HAVING COUNT(*) > 1

Read card text
What this card says
What it is
Aggregate functions sum up many rows: COUNT, SUM, AVG, MIN, MAX.
GROUP BY makes groups. HAVING filters groups.
Order of steps
FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT.
Common mistake
WHERE COUNT(*) > 1 gives an error. WHERE runs before grouping.
Use HAVING COUNT(*) > 1.
| Clause | Filters | Can use aggregates? |
|---|---|---|
| WHERE | Individual rows, before grouping | No |
| HAVING | Groups, after grouping | Yes |
Learn more in the lesson: 10.8 Aggregate Functions, GROUP BY and HAVING