Top Spending Customer
MediumSQLDatabaseSorting
Description
Write a SQL query to return the single customer who has spent the most in total across all orders, as a value named customer. **Output columns (in order):** customer
Table:
orders| Column | Type |
|---|---|
| id | INT |
| customer | TEXT |
| amount | INT |
Examples
Input:
CREATE TABLE orders (id INT, customer TEXT, amount INT); INSERT INTO orders VALUES (1,'Ann',100),(2,'Ben',50),(3,'Ann',30);Output:
AnnExplanation:
Total spend is summed per customer and the highest spender is returned, breaking a tie by name.
Input:
CREATE TABLE orders (id INT, customer TEXT, amount INT); INSERT INTO orders VALUES (1,'Solo',5);Output:
SoloExplanation:
Total spend is summed per customer and the highest spender is returned, breaking a tie by name.
Input:
CREATE TABLE orders (id INT, customer TEXT, amount INT); INSERT INTO orders VALUES (1,'A',10),(2,'B',20);Output:
BExplanation:
Total spend is summed per customer and the highest spender is returned, breaking a tie by name.
Constraints
- •
Use standard SQL (SQLite).