Bake-Off Division Champions
Problem
Table: `Bakers`
```text
+------------+------------+
| Column | Type |
+------------+------------+
| baker_id | int |
| division | int |
+------------+------------+
baker_id is the primary key. Each baker competes in exactly one division.
```
Table: `Bakeoffs`
```text
+--------------+------+
| Column | Type |
+--------------+------+
| bakeoff_id | int |
| left_baker | int |
| right_baker | int |
| left_score | int |
| right_score | int |
+--------------+------+
bakeoff_id is the primary key. Each row is one head-to-head bake-off between
two bakers and the score each of them earned.
```
The champion of each division is the baker with the highest total score summed across every bake-off they took part in. If two bakers in a division tie on total score, the champion is the one with the smaller `baker_id`. A baker who never appears in a bake-off has a total score of 0.
Return one row per division with columns `division` and `baker_id`.
**Example**
Baker 11 in division 1 scores 3 + 2 = 5, the most in that division, so 11 is the champion of division 1.
Tables
Example rows — the live problem includes the full dataset.
| baker_id | division |
|---|---|
| 11 | 1 |
| 22 | 1 |
| 33 | 1 |
| bakeoff_id | left_baker | right_baker | left_score | right_score |
|---|---|---|---|---|
| 1 | 11 | 44 | 3 | 0 |
| 2 | 33 | 22 | 1 | 2 |
| 3 | 33 | 11 | 2 | 0 |
Expected output
Your answer should return 3 rows with the columns division, baker_id.
Starter code (SQL)
SELECT *
FROM Bakers;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