Back to Practice
#0205
Average Order Value by User
EasySQL15 min10 XP
Problem
Write a query returning user_id and avg_order_value from orders.
Why This Matters
Average order value is a common product and ecommerce metric, and it is a clean GROUP BY exercise.
Schema
orders(order_id INT, user_id INT, amount REAL)
Examples
Example 1
Inputorders: (1,10,20), (2,10,40), (3,11,15)
Output10 -> 30, 11 -> 15
User 10 has average (20 + 40) / 2 = 30.
Constraints
- Return the exact requested result.
- Handle common edge cases.
- Keep the solution readable before optimizing.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputorders: (1,10,20), (2,10,40), (3,11,15)
Expected10 -> 30, 11 -> 15
User 10 has average (20 + 40) / 2 = 30.
Hidden Test Categories
empty or minimal inputrepeated valueslarger realistic input