Completed versus other orders

conditional logic

Completed versus other orders

Stripe SQL Interview Question

Stripe's support team wants a quick health check on each customer of an online store: how many of their orders were paid in full, and how many were canceled or refunded.

For each customer_id, count their completed orders as completed_orders and all their other orders as other_orders.

Asked of

  • Data Analyst
  • BI Analyst
  • Product Analyst
  • Analytics Engineer
  • Data Engineer
  • Data Scientist

ordersTable35 rows

Column NameType
order_idBIGINT
customer_idBIGINT
order_dateDATE
statusVARCHAR
amountDOUBLE

ordersExample Input

order_idcustomer_idorder_datestatusamount
100112024-01-05completed120.5
100222024-01-07completed2400
100312024-01-11completed89.99
100432024-01-15canceled45
100542024-01-18completed610.75
100622024-01-22completed1850.25
100752024-01-29completed3200
100812024-02-02refunded75
100962024-02-06completed55.4
101032024-02-09completed132.6

Example Output

customer_idcompleted_ordersother_orders
121
220
311
410
510
610

Explanation

Customer 1 has two completed orders, 1001 and 1003, and one refunded order, 1008, so they get 2 and 1. Customer 3 has one completed order and one canceled order, so they get 1 and 1. Customer 2 has two completed orders and nothing else.

The example above is a small slice of the data. Your query runs against the full tables.