SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

Assign the Active Promo to Each Trip

Unsolved

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.

SQL Query Editor (Ctrl+Enter to run)
0 characters · Valid
Canonical Solution Official

Official Solution is Hidden

Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.

Community Q&A & Discussion

Ask questions, share alternate queries, and explore solutions

0 comments
Asked By:
🏢 Uber

Submission History

Your recent query executions and answer checks

Execution Pipeline:
FROM trips
Full source dataset
7 rows total
Ready. Type a query to see live execution.
Clause: Auto-Sync · AlaSQL Engine