Minimum Donation Tier That Fits Each Venue
Problem
Table: `venues`
| Column Name | Type |
|---|---|
| venue_id | int |
| seats | int |
`venue_id` is the primary key. `seats` is how many attendees the venue can hold.
Table: `tiers`
| Column Name | Type |
|---|---|
| donation | int |
| attendees | int |
`donation` is the primary key. Each row means: at this donation level, `attendees` people are expected to attend.
For each venue, find the smallest `donation` tier whose expected `attendees` does not exceed the venue's `seats` (so the crowd fits). Return `venue_id` and that minimum donation in a column named `min_donation`. If no tier fits, return `-1` for that venue. Return the result in any order.
Tables
Example rows — the live problem includes the full dataset.
| venue_id | seats |
|---|---|
| 1 | 50 |
| 2 | 200 |
| 3 | 10 |
| donation | attendees |
|---|---|
| 100 | 30 |
| 200 | 120 |
| 300 | 180 |
Expected output
Your answer should return 3 rows with the columns venue_id, min_donation.
Starter code (SQL)
SELECT *
FROM venues;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