Practice · History · Easy
Rank pharaohs by reign length (reign_end − reign_start) and return the top 5 as name and years_reigned, longest first.
Runs in your browser. No signup needed.
pharaohs(name, reign_start, reign_end). Years are signed, so reign_end − reign_start gives a positive length.
SELECT name, (reign_end - reign_start) AS years_reigned
FROM pharaohs
ORDER BY ...
LIMIT 5;
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.
Pepi II tops the list at a traditional 94 years — but several Egyptologists argue for ~64. The knowledge base flags this dispute rather than picking a side. (Turin King List; Wikipedia)