Customers without orders

joins

Customers without orders

Amazon SQL Interview Question

Amazon's marketing team wants to send a welcome offer to people who created an account but never bought anything.

Identify every customer who has never placed an order, showing their customer_id and name. An order of any status counts as an order.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Analytics Engineer
  • Data Engineer
  • AI Engineer

customersTable10 rows

Column NameType
customer_idBIGINT
nameVARCHAR
countryVARCHAR
segmentVARCHAR
signup_dateDATE

ordersTable35 rows

Column NameType
order_idBIGINT
customer_idBIGINT
order_dateDATE
statusVARCHAR
amountDOUBLE

customersExample Input

customer_idnamecountrysegmentsignup_date
1Priya SharmaIndiaconsumer2023-01-14
2Marcus WebbUnited Statesenterprise2023-02-03
3Ana SousaBrazilconsumer2023-02-27
4Liam O'ConnorIrelandsmall_business2023-03-15
5Yuki TanakaJapanenterprise2023-04-02
6Fatima Al-RashidUnited Arab Emiratesconsumer2023-05-21
7Daniel OkaforNigeriasmall_business2023-06-08

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_idname
7Daniel Okafor

Explanation

Customers 1 to 6 each placed at least one order in the example. Daniel Okafor, customer 7, has no orders at all, so that is the only customer returned.

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