Customer Product Diversity

Business problem: identify customers who might respond well to cross-selling (they already buy a variety of products) versus those who always buy the same thing, using order_items for a genuine per-item breakdown.

What data is needed: how many distinct products each customer has ordered. How tables relate: customers → orders → order_items (a three-table join, using the junction table). Write a query returning each customer's name and their count of distinct products ordered, sorted highest first. Verify: manually check one customer's distinct product count against their own order_items rows.

query.sql
Loading editor…

Test cases

  • Full result: distinct product count per customer, highest first
  • Returns all five customers

Use Run to explore freely against the sample database. Use Submit to grade your query against every test case, including any hidden ones.