AnalystPath

Bake-Off Division Champions

SQLHardSenior level~15 min

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.

Bakers
baker_iddivision
111
221
331
Bakeoffs
bakeoff_idleft_bakerright_bakerleft_scoreright_score
1114430
2332212
3331120

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

Related SQL questions