SQL Query to Find Top 10 Customers by Total Spend

This technical problem asks the reader to write a SQL query to find the top 10 customers by total spend. The table of customer data is provided as an example, and the expected output is also provided.

Problem

Given a table of customer data, write a SQL query to find the top 10 customers by total spend.
Example input:
customers
id name total_spend
1 John Doe $100
2 Jane Smith $200
3 Bob Jones $300
Example output:
id name total_spend
3 Bob Jones $300
2 Jane Smith $200
1 John Doe $100

Solution

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

/*

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

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a good understanding of SQL. The solution is optimal, using the ORDER BY and LIMIT clauses to sort the table by total_spend in descending order and then limit the results to the top 10 customers.

Evaluated at: 2023-01-31 00:15:36