Given tables for orders, merchants, and Dashers, write a query using LAG or LEAD to identify the time gap between consecutive deliveries for each driver.
Use completed deliveries with non-null delivery timestamps. Return only deliveries that have a previous delivery for the same Dasher.
Output
- One row per delivery with a previous delivery by that Dasher.
- Include
dasher_id, dasher_name, order_id, merchant_name, delivery_completed_at, previous_delivery_at, and gap_minutes.
- Order by
dasher_id, delivery_completed_at, and order_id.