Which Customers Need a Win-Back Campaign?

Which Customers Need a Win-Back Campaign?

You are a product analyst at a B2B marketplace. The CRM team is preparing a win-back campaign and needs to know how many days have passed since each active buyer's most recent genuinely paid purchase as of July 1, 2026. Cancelled, refunded, unfinished orders and records without a payment timestamp must not affect the metric. Customers with no qualifying order must be excluded. Return columns: - customer_id — customer identifier, integer - customer_name — customer name - last_paid_date — date of the latest paid order in YYYY-MM-DD format - recency_days — calendar days from last_paid_date to 2026-07-01, integer Rules: - Use only orders with status paid and a non-NULL paid_at. - Ignore orders after 2026-07-01. - If a customer has several payments on the same latest date, return one customer row. - Sort by recency_days ascending, then customer_id ascending. - No rounding is needed; the result must contain no NULL values.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.

customer_idcustomer_namelast_paid_daterecency_days
4Delta Foods2026-06-301
8Harbor Tools2026-06-301
1Acorn Labs2026-06-283
PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid