Time Between First and Second Order

For each customer with at least two orders (any status), return the dates of their first and second orders and the number of days between them. Orders on the same date are ordered by order_id.

Expected output

customer_id, first_order_date, second_order_date, days_between (integer). Any row order.

Row order is not checked. Column names are not checked; numbers are compared to 2 decimals.

Dataset: E-commerce store

An online store selling electronics, home goods, books, apparel and beauty products to customers in six countries (Jan 2025 to Mar 2026).

customers

One row per registered customer.

customer_idINTEGERprimary key
nameTEXT
countryTEXTUS, UK, DE, IN, BR or CA
signup_dateTEXTYYYY-MM-DD
referred_byINTEGERcustomer_id of the referrer, NULL if none
products

Product catalog with current list price.

product_idINTEGERprimary key
nameTEXT
categoryTEXT
priceREALlist price in USD
orders

One row per order. Only completed orders count as revenue.

order_idINTEGERprimary key, increases with order_date
customer_idINTEGER
order_dateTEXTYYYY-MM-DD
statusTEXTcompleted, cancelled or returned
order_items

Line items. Revenue of a line = quantity * unit_price (unit_price may include a discount).

order_idINTEGER
product_idINTEGER
quantityINTEGER
unit_priceREALprice actually charged per unit

Engine: SQLite. Dates are text (YYYY-MM-DD); use strftime(), date() and julianday() for date math.

Related problems

SQLite · runs in your browser
Ctrl/⌘ + Enter to run
Expected output preview (43 rows, any order)
customer_idfirst_order_datesecond_order_datedays_between
12025-10-052025-10-094
22025-08-072025-08-2215
32025-08-142026-01-03142

Showing 3 of 43 rows.

Hints

Worked solution

Run at least one query to unlock it.