Practice · History · Hard
Using a CTE, return country, obelisks (the count) and tallest_obelisk (its name), ordered by obelisks descending then country.
Runs in your browser. No signup needed.
obelisks(name, current_country, height_m). Build the per-country aggregate in a WITH clause, then join back to find which obelisk holds the maximum height.
WITH per_country AS (
SELECT current_country AS country, COUNT(*) AS obelisks, MAX(height_m) AS tallest_m
FROM obelisks GROUP BY current_country
)
SELECT c.country, c.obelisks, o.name AS tallest_obelisk
FROM per_country c
JOIN obelisks o ON ...
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.
Aggregates lose the row they came from, so recovering "which one was the maximum" means joining the aggregate back to the original table.