Average Order Value
Beginner Mode
Objective
Given a table named Orders that records customer purchases, write an SQL query to determine the average expenditure per customer. Your result should display each customer_id alongside their avg_order_value, rounded to two decimal places. Ensure the output is sorted in ascending order based on customer_id.
Additional information
Table Schema:
The
orderstable:Column Type Description order_id INTEGER Unique identifier for each order customer_id INTEGER Identifier for the customer who made the order total_amount DECIMAL Total amount spent on the order order_date DATE Date when the order was placed Constraints:
- Each
customer_idmay have multiple associated orders. - There is at least one order present in the table.
- Each
Output Requirements:
- Columns:
customer_id,avg_order_value avg_order_valuemust be rounded to two decimal places.- Results must be ordered by
customer_idin ascending order.
- Columns:
Examples
Example 1:
Output:
Input:
| orders | |||
|---|---|---|---|
| customer_id | order_date | order_id | total_amount |
| 101 | 2023-01-01 | 1 | 150.5 |
| 101 | 2023-01-15 | 2 | 200.75 |
| 102 | 2023-01-02 | 3 | 75.25 |
| 102 | 2023-01-20 | 4 | 125 |
| 103 | 2023-01-10 | 5 | 300 |
| avg_order_value | customer_id |
|---|---|
| 175.63 | 101 |
| 100.13 | 102 |
| 300 | 103 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Accenture