SQL interview question: Average Order Value per Customer
Average Order Value by Customer
The payments team needs to calculate average transaction size per customer to identify high-value customers.
Calculate the average order value (total_amount) for each customer, rounded to 2 decimal places.
Return customer_id and avg_order_value. Order by customer_id.
Skills: AVG aggregation and ROUND
Tables
orders 15 rows
- order_id integer PK
- customer_id integer → customers
- order_date text
- total_amount real
- status text
| order_id | customer_id | order_date | total_amount | status |
|---|---|---|---|---|
| 1 | 101 | 2024-01-20 | 249.99 | delivered |
| 2 | 101 | 2024-03-15 | 1999.99 | delivered |
| 4 | 101 | 2024-09-05 | 79.99 | delivered |