AnalystPath

Always Mid-Pack Bakers

SQLHardSenior level~15 min

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.

bakers
baker_idbaker_name
1Hana
2Ravi
3Sora
round_scores
round_idbaker_idscore
10170
10280
10390

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

Related SQL questions