Gaps between orders of 120+ days: shipped, Mar–Oct 2025
Instructions
Consider orders with status = 'shipped' whose created_at is on or after March 1, 2025 and strictly before November 1, 2025. For each customer, order such orders by created_at (ties by id) and find the gap in days between the date (created_at::date) of each order and the customer's previous considered order. Output the customers who have at least one gap of 120 days or more: customer_id, orders_cnt, the number of the customer's considered orders, and max_gap_days, the largest gap in days. A customer's first order has no gap. Sort by max_gap_days descending, then by customer_id ascending.
Hints
Each next one is more detailed and costs more
Query
Result
Click Run to see the query result, or Check to submit your solution.
Dataset schema
Table relationships
- N:1Many-to-one
order_items.→order_id orders.id - N:1Many-to-one
order_items.→product_id products.id - N:1Many-to-one
orders.→customer_id customers.id - N:1Many-to-one
products.→category_id categories.id
Table data
Select a table in the diagram or list to view its rows.