Back to Practice
#0173
Customers Above Average Spend
MediumSQL25 min20 XP
Problem
Return customer_id values whose total order amount is greater than the average total amount per customer.
Why This Matters
This pattern combines CTEs, aggregation, and comparison against a derived benchmark.
Schema
orders(customer_id INTEGER, amount INTEGER)
Examples
Example 1
Inputcustomer totals: 1 -> 300, 2 -> 50, 3 -> 100
Outputcustomer 1
Average customer total is 150, and only 300 is above it.
Constraints
- Return the exact requested output.
- Handle ordinary edge cases.
- Prefer simple, interview-readable code.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputcustomer totals: 1 -> 300, 2 -> 50, 3 -> 100
Expectedcustomer 1
Average customer total is 150, and only 300 is above it.
Hidden Test Categories
empty or minimal inputduplicates or tieslarger input