Practice · History · Hard
Return one row per country — country, name and height_m of its tallest obelisk — ordered by height_m descending.
Runs in your browser. No signup needed.
obelisks(current_country, name, height_m). Rank inside a subquery, then keep the first of each partition.
SELECT country, name, height_m
FROM (
SELECT current_country AS country, name, height_m,
ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...) AS rn
FROM obelisks
)
WHERE rn = 1
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.
"Top-N per group" has no single keyword in SQL — ranking in a subquery and filtering the rank is the standard idiom.