AnalystPath

Chess Club Standings

SQLMediumMid level~15 min

Problem

Table: `Players`

```text
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| player_id | int |
| player_name | varchar |
+-------------+---------+
player_id is the primary key for this table.
```

Table: `Games`

```text
+-------------+------+
| Column Name | Type |
+-------------+------+
| white_id | int |
| black_id | int |
| white_score | int |
| black_score | int |
+-------------+------+
(white_id, black_id) is the primary key for this table.
Each row is one game: who played White, who played Black, and the rounds each side won.
```

Write a solution to build the club standings. For each player report:
- `player_name`
- `games_played`
- `league_points`: Win = 3, Draw = 1, Loss = 0
- `rounds_for`: total rounds the player won
- `rounds_against`: total rounds the player conceded
- `rounds_diff`: rounds_for minus rounds_against

Return the result table ordered by `league_points` DESC, then `rounds_diff` DESC, then `player_name` ASC.

Tables

Example rows — the live problem includes the full dataset.

Players
player_idplayer_name
1Knight
2Bishop
3Rook
Games
white_idblack_idwhite_scoreblack_score
1231
2322
3104

Expected output

Your answer should return 3 rows with the columns player_name, games_played, league_points, rounds_for, rounds_against, rounds_diff.

Starter code (SQL)

SELECT *
FROM Players;

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