Practice · Sports · Medium
Count how many athletes each sport has, and return only the sports with MORE than one athlete, as sport and n, most first.
Runs in your browser. No signup needed.
Use athletes. GROUP BY sport, then HAVING COUNT(*) > 1.
SELECT sport, COUNT(*) AS n
FROM athletes
GROUP BY sport
HAVING COUNT(*) > 1
ORDER BY n DESC;
The reference solution is checked automatically when you run your query on the practice page — results are compared row by row, and order matters for this one.
HAVING filters groups AFTER aggregation, where WHERE filters rows before it — mixing them up is one of the most common SQL interview mistakes. (SQLite docs)