Revenue by country

joins

Revenue by country

Stripe SQL Interview Question

Stripe's international team wants to show an online store which countries its revenue comes from, so the store can decide where to expand next.

Find the total revenue from completed orders for each customer country, as revenue. Sort the rows by revenue, highest first.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Product Analyst
  • Analytics Engineer

ordersTable35 rows

Column NameType
order_idBIGINT
customer_idBIGINT
order_dateDATE
statusVARCHAR
amountDOUBLE

customersTable10 rows

Column NameType
customer_idBIGINT
nameVARCHAR
countryVARCHAR
segmentVARCHAR
signup_dateDATE

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

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

Example Output

countryrevenue
United States4250.25
Japan3200
Ireland610.75
India210.49
Brazil132.6
United Arab Emirates55.4

Explanation

Marcus Webb, the only customer in the United States, completed orders worth 2,400 and 1,850.25, so the United States leads with 4,250.25. Priya Sharma's refunded order is not counted, so India's revenue is 120.50 plus 89.99, which is 210.49.

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