Chess Club Standings
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.
| player_id | player_name |
|---|---|
| 1 | Knight |
| 2 | Bishop |
| 3 | Rook |
| white_id | black_id | white_score | black_score |
|---|---|---|---|
| 1 | 2 | 3 | 1 |
| 2 | 3 | 2 | 2 |
| 3 | 1 | 0 | 4 |
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