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 orders table:

    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_id may have multiple associated orders.
    • There is at least one order present in the table.
  • Output Requirements:

    • Columns: customer_id, avg_order_value
    • avg_order_value must be rounded to two decimal places.
    • Results must be ordered by customer_id in ascending order.

Examples

Example 1:

Input:

orders
customer_idorder_dateorder_idtotal_amount
1012023-01-011150.5
1012023-01-152200.75
1022023-01-02375.25
1022023-01-204125
1032023-01-105300

Output:
avg_order_valuecustomer_id
175.63101
100.13102
300103
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →