HAVING Clause in SQL
Level 392 keystrokes
HAVING filters groups after GROUP BY, similar to WHERE but for aggregated results.
SQL code
1SELECT2 department, -- COUNT(*) gives the number of employees per department3 COUNT(*) AS count4FROM5 employees-- GROUP BY creates one group per department6GROUP BY7 department-- HAVING filters groups after aggregation (WHERE filters rows before it)-- Only departments with more than 3 employees are kept8HAVING9 COUNT(*) > 3;Output
+------------+-------+ | department | count | +------------+-------+ | Sales | 5 | | IT | 8 | +------------+-------+ 2 rows in set
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this SQL code and how often they appear.
(× 2)× 2*× 2,× 1;× 1>× 1