Given a table of customer data, this SQL query returns the top 10 customers with the highest average order value.
Given a table of data with customer information, write a SQL query to find the top 10 customers with the highest average order value. Example input: CustomerID | Name | OrderValue 1 | John | 10 2 | Smith | 20 3 | Jane | 30 4 | Bill | 40 5 | Karen | 50 6 | Steve | 60 7 | Rachel | 70 8 | Mike | 80 9 | Tina | 90 10 | Jake | 100 Output: CustomerID | Name | AverageOrderValue 6 | Steve | 60 7 | Rachel | 70 8 | Mike | 80 9 | Tina | 90 10 | Jake | 100
SELECT CustomerID, Name, AVG(OrderValue) AS AverageOrderValue FROM Customers GROUP BY CustomerID, Name ORDER BY AverageOrderValue DESC LIMIT 10; /* The solution is optimal because it uses the GROUP BY and ORDER BY clauses to group the customers by their ID and name, and then order them by their average order value. */
The candidate's solution is complete and solves the problem. The approach is clear and concise.
Evaluated at: 2022-11-15 12:15:30