AnalystPath

Unassigned Locker Numbers

SQLMediumMid level~15 min

Problem

A gym assigns lockers to members with sequential locker numbers, but some numbers in the sequence are currently empty. The `Locker` table holds the assigned lockers.

`Locker`:
- `locker_no` (int) — an assigned locker number
- `holder_name` (varchar)

Return every locker number between 1 and the largest assigned `locker_no` that is **not** currently assigned. Name the single output column `gap_no`.

Tables

Example rows — the live problem includes the full dataset.

Locker
locker_noholder_name
1Hugo
4Iris
5Jonas

Expected output

Your answer should return 2 rows with the columns gap_no.

Starter code (SQL)

SELECT *
FROM Locker;

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