Practice · History · Hard
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.
obelisks(current_country, name, height_m). Use ROW_NUMBER() with PARTITION BY.
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.
PARTITION BY restarts the numbering for each group — the window-function equivalent of GROUP BY without collapsing the rows.