SQL Query to Find Top 10 Customers by Total Spent

Write a SQL query to find the top 10 customers by total spent.

Problem

Given a table of data with customer information, write a SQL query to find the top 10 customers by total spent.
Example input:
| customer_id | name | total_spent |
|--------------|------|-------------|
| 1            | John | 100         |
| 2            | Jane | 200         |
| 3            | Joe  | 300         |
| 4            | Jill | 400         |
Example output:
| customer_id | name | total_spent |
|--------------|------|-------------|
| 4            | Jill | 400         |
| 3            | Joe  | 300         |
| 2            | Jane | 200         |
| 1            | John | 100         |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT customer_id, name, total_spent
FROM customers
ORDER BY total_spent DESC
LIMIT 10;

/*

The solution is optimal because it uses the ORDER BY and LIMIT clauses to sort the table by total_spent in descending order and then limit the results to the top 10 customers.

*/

A.I. Evaluation of the Solution

The solution is optimal because it uses the ORDER BY and LIMIT clauses to sort the table by total_spent in descending order and then limit the results to the top 10 customers.

Evaluated at: 2023-01-28 00:15:28