Uber's supply team wants an early warning when a driver is disengaging. weekly_driver_trips has one row per driver per week, including weeks with 0 trips. A week counts as a drop when its completed_trips is at least 30% lower than the previous week's, which means this_week <= 0.7 × previous_week, and the previous week must be greater than 0 (a week after a 0 week can never be a drop). An alert fires in a week that is a drop and whose previous week was also a drop. Write an SQL query that returns driver_id, alert_week (the week_start of the second drop), trips_two_weeks_before, trips_week_before and trips_this_week for every alert. Order the results by driver_id, then alert_week.
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.