National Champions

SQL practice problem 46 of 67 · Window Functions · Medium · 25 coins for your first accepted solve

Each country crowns its highest-level player. If several players tie for the top level in a country, they all become champions.

Return country, name, level for every champion. Ignore players with no country. Row order does not matter.

Schema

CREATE TABLE players (
  id         INT PRIMARY KEY,
  name       TEXT NOT NULL,
  country    TEXT,            -- NULL = unknown
  level      INT NOT NULL,
  joined_on  DATE NOT NULL,
  mentor_id  INT              -- another player's id, or NULL
);

Write your query in the browser, run it on the sample data, then submit it against hidden test data.

Previous: Free Agents · Next: Mind the Gap · All problems