Library Entries Without a Checkout
Problem
A public library records every member entry in `LibraryEntries` and every item borrowed in `Checkouts`. A single entry can result in zero, one, or many checkouts.
`LibraryEntries`:
- `entry_id` (int) — unique id of one entry into the library
- `member_id` (int) — member who entered
`Checkouts`:
- `checkout_id` (int) — unique id of one borrowed item
- `entry_id` (int) — the entry during which the item was borrowed
- `item_count` (int) — how many copies were taken
Find every member who entered the library but borrowed nothing during that entry, and how many such empty-handed entries each made. Rows may be in any order.
Tables
Example rows — the live problem includes the full dataset.
| entry_id | member_id |
|---|---|
| 1 | 23 |
| 2 | 9 |
| 4 | 30 |
| checkout_id | entry_id | item_count |
|---|---|---|
| 2 | 5 | 2 |
| 3 | 5 | 1 |
| 9 | 5 | 4 |
Expected output
Your answer should return 3 rows with the columns member_id, empty_entries.
Starter code (SQL)
SELECT *
FROM LibraryEntries;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