Level Ranks
SQL practice problem 54 of 67 · Window Functions · Medium · 25 coins for your first accepted solve
Number the distinct levels from the top: everyone on the highest level gets 1, everyone on the next level down gets 2, and so on — with no gaps.
Return name, level, level_rank, sorted by level descending, then name.
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: Growth Curve · Next: Rolling Average · All problems