Find the average order value for each customer.

This technical problem asks the reader to write a SQL query to find the average order value for each customer, given a table of customer orders. An example input and output is provided.

Problem

Given a table of customer orders, write a SQL query to find the average order value for each customer.
Example input:
customer_id | order_id | order_value
1 | 100 | 10
2 | 101 | 20
3 | 102 | 30
Example output:
customer_id | avg_order_value
1 | 10
2 | 20
3 | 30

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT customer_id, AVG(order_value) AS avg_order_value
FROM orders
GROUP BY customer_id;

/*

The solution above is optimal because it uses the GROUP BY clause to group the orders by customer_id, and then uses the AVG function to calculate the average order value for each customer.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it uses the GROUP BY clause to group the orders by customer_id, and then uses the AVG function to calculate the average order value for each customer.

Evaluated at: 2022-11-26 08:15:56