Shopify interview question
Report every customer's order count and total spend, including customers without orders
- Company:
- Shopify
- Type:
- SQL
- Difficulty:
- Easy
- Reported:
- June 2, 2026
Problem
Two tables describe customers and their orders.
customers
customer_idINT, primary keynameVARCHARcountryVARCHAR
orders
order_idINT, primary keycustomer_idINT, referencescustomersamountDECIMAL(10, 2)order_dateDATE
Write a query returning name, order_count and total_amount for every customer, including customers with no orders (count 0, total 0). Sort by total_amount descending, then name ascending.
Example 1
Input:
customers: (1, 'Ana', 'BR'), (2, 'Ben', 'US'), (3, 'Chi', 'NG')
orders: (10, 1, 20.00, '2024-01-03'), (11, 1, 5.50, '2024-02-01'), (12, 3, 40.00, '2024-02-02')
Output:
name | order_count | total_amount
Chi | 1 | 40.00
Ana | 2 | 25.50
Ben | 0 | 0
Ben has no orders but still appears.
Constraints
- Up to
10^6customers and10^7orders. - Customer names are not unique, so group by the id.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern