Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

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_id INT, primary key
  • name VARCHAR
  • country VARCHAR

orders

  • order_id INT, primary key
  • customer_id INT, references customers
  • amount DECIMAL(10, 2)
  • order_date DATE

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^6 customers and 10^7 orders.
  • 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