Mentor Lineage
SQL practice problem 59 of 67 · Boss Fights · Hard · 50 coins for your first accepted solve
Mentorship forms chains: a player's mentor may have a mentor, and so on. There are no cycles.
For every player return name and depth — how many mentors are above them in the chain. Players without a mentor have depth 0. 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: Customer of the Month · Next: Monthly Growth · All problems