Practice · History · Hard

The tallest in each country

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.

What you are given

obelisks(current_country, name, height_m). Rank inside a subquery, then keep the first of each partition.

Starting point

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.

Did you know

"Top-N per group" has no single keyword in SQL — ranking in a subquery and filtering the rank is the standard idiom.

More History challenges

Open it in the playground →