DataLane

24. Second order within seven days

hardProNot started~18 minWindow functionsTime series

Asked in screens shaped like: Shopify, DoorDash, Uber

Retention wants customers whose second completed order landed within 7 days of their first completed order. Return customer_id and the days between those two orders, smallest customer_id first.

Requirements

  • Columns: customer_id, days_between
  • Only completed orders
  • days_between is the day gap between 1st and 2nd completed order
  • Keep rows where days_between <= 7
  • Order by customer_id

Expected output

customer_id, days_between

Row order is graded, so ORDER BY matters here.

SQL editor

Loading SQL engine…

Ctrl/Cmd + Enter submits

Run your query to see the result set.

Pro problem

Hard problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close