Always Mid-Pack Bakers
Problem
A baking competition runs several rounds. In each round the judges give every competing baker a score. A baker is **mid-pack** if they entered at least one round and, in every round they entered, they were never the highest scorer nor the lowest scorer of that round.
Table: `bakers`
| Column | Type |
|------------|---------|
| baker_id | int |
| baker_name | varchar |
`baker_id` is the primary key.
Table: `round_scores`
| Column | Type |
|------------|------|
| round_id | int |
| baker_id | int |
| score | int |
`(round_id, baker_id)` is the primary key. Each row is one baker's score in one round.
Write a query that returns the `baker_id` and `baker_name` of every mid-pack baker. A baker who never competed is not mid-pack. Order the result by `baker_id`.
Tables
Example rows — the live problem includes the full dataset.
| baker_id | baker_name |
|---|---|
| 1 | Hana |
| 2 | Ravi |
| 3 | Sora |
| round_id | baker_id | score |
|---|---|---|
| 10 | 1 | 70 |
| 10 | 2 | 80 |
| 10 | 3 | 90 |
Expected output
Your answer should return 1 row with the columns baker_id, baker_name.
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