Practice · History · Medium
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.
pharaohs(name, reign_start, reign_end). Compare (reign_end − reign_start) to a scalar subquery: (SELECT AVG(reign_end − reign_start) FROM pharaohs).
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.
A scalar subquery returns one value you can compare against — here, the table’s own average. (SQLite docs)