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
ColumnType
idINT
customerTEXT
amountINT

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:Ann
Explanation:

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:Solo
Explanation:

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:B
Explanation:

Total spend is summed per customer and the highest spender is returned, breaking a tie by name.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.