Uber riders can hold several promotions whose validity windows overlap. A promotion applies to a trip when it belongs to the same rider and start_at <= requested_at < end_at (start inclusive, end exclusive). If more than one promotion applies to a trip, use the one with the latest start_at. If start_at is also tied, use the one with the larger promo_id. Trips with no applicable promotion must still appear, with a NULL promo_id. Write an SQL query that returns trip_id and promo_id for every trip. Order the results by trip_id ascending.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.