Practice · History · Hard

Rank obelisks within their country

For every obelisk return current_country, name, height_m and rank_in_country — its height rank inside its own country, tallest = 1. Order by country, then rank.

Runs in your browser. No signup needed.

What you are given

obelisks(current_country, name, height_m). Use ROW_NUMBER() with PARTITION BY.

Starting point

SELECT current_country, name, height_m,
       ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...) AS rank_in_country
FROM obelisks
ORDER BY ...;

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

PARTITION BY restarts the numbering for each group — the window-function equivalent of GROUP BY without collapsing the rows.

More History challenges

Open it in the playground →