SQL interview question: Nth Purchase per Customer

Find Customer's Third Purchase

The analytics team wants to understand customer behavior by analyzing their third purchase specifically.

Return customer_id, order_id, and order_date for each customer's third order chronologically.

Only include customers who have at least 3 orders. Use ROW_NUMBER() window function.

Inspired by Uber's "User's Third Transaction" problem

Tables

orders 15 rows
  • order_id integer PK
  • customer_id integer → customers
  • order_date text
  • total_amount real
  • status text
order_idcustomer_idorder_datetotal_amountstatus
11012024-01-20249.99delivered
21012024-03-151999.99delivered
41012024-09-0579.99delivered

Keep going