Proud Mentors

SQL practice problem 62 of 67 · Boss Fights · Hard · 50 coins for your first accepted solve

For every player who mentors someone, return mentor (their name), mentees (how many players they mentor) and mentee_wins — the total number of matches won by their mentees (0 if none).

Careful: counting mentees and their wins in one join counts some rows twice. 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
);

CREATE TABLE matches (
  id            INT PRIMARY KEY,
  winner_id     INT NOT NULL REFERENCES players(id),
  loser_id      INT NOT NULL REFERENCES players(id),
  played_at     DATE NOT NULL,
  duration_sec  INT NOT NULL
);

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

Previous: Hot Streak · Next: Quiet Days · All problems