AnalystPath

Minimum Donation Tier That Fits Each Venue

SQLMediumMid level~15 min

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.

venues
venue_idseats
150
2200
310
tiers
donationattendees
10030
200120
300180

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

Related SQL questions