Practice · Sports · Medium

Sports with more than one athlete

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.

What you are given

Use athletes. GROUP BY sport, then HAVING COUNT(*) > 1.

Starting point

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.

Did you know

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)

More Sports challenges

Open it in the playground →