AnalystPath

Match Counts Between Chess Players

SQLMediumMid level~15 min

Problem

Table: `match_log`

| Column Name | Type |
|---|---|
| white_id | int |
| black_id | int |
| moves | int |

This table has no primary key. Each row records one chess match: `white_id` played the white pieces, `black_id` played black, and `moves` is how many moves the game lasted. The same two players may meet many times, sometimes swapping colours.

For each **unordered pair** of players who have faced each other, report the number of matches between them and the total number of moves across those matches. The match between A and B is the same pairing as B and A. Output columns `player_a`, `player_b` (with `player_a < player_b`), `matches`, and `total_moves`.

Tables

Example rows — the live problem includes the full dataset.

match_log
white_idblack_idmoves
1230
2140
1325

Expected output

Your answer should return 3 rows with the columns player_a, player_b, matches, total_moves.

Starter code (SQL)

SELECT *
FROM match_log;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions