Find customers who have spent more than $1000 in total

Write a SQL query to find the customers who have spent more than $1000 in total, given a table of customer orders.

Problem

Given a table of data representing customer orders from a online store, write a SQL query to find the customers who have spent more than $1000 in total.
Example input:
| customer_id | order_id | order_total |
|-------------|----------|-------------|
| 1           | 1001     | 500         |
| 1           | 1002     | 600         |
| 2           | 1003     | 200         |
| 3           | 1004     | 700         |
| 3           | 1005     | 800         |
Example output:
| customer_id |
|-------------|
| 1           |
| 3           |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT customer_id
FROM orders
GROUP BY customer_id
HAVING SUM(order_total) > 1000;

/*

The solution above is optimal because it uses the GROUP BY and HAVING clauses to group the orders by customer_id and then filter the results to only include customers who have spent more than $1000.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it uses the GROUP BY and HAVING clauses to group the orders by customer_id and then filter the results to only include customers who have spent more than $1000.

Evaluated at: 2022-11-13 02:15:51