Practice · History · Medium

Longer than average

Return the names of pharaohs whose reign length was longer than the average reign length across all pharaohs, alphabetically.

Runs in your browser. No signup needed.

What you are given

pharaohs(name, reign_start, reign_end). Compare (reign_end − reign_start) to a scalar subquery: (SELECT AVG(reign_end − reign_start) FROM pharaohs).

Starting point

SELECT name
FROM pharaohs
WHERE (reign_end - reign_start) > (SELECT AVG(reign_end - reign_start) FROM pharaohs)
ORDER BY name;

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

A scalar subquery returns one value you can compare against — here, the table’s own average. (SQLite docs)

More History challenges

Open it in the playground →