Biggest Spender
Return one row: the customer_id whose orders add up to the most, and that sum as spent. If customers tie, return the one with the smallest customer_id.
Example 1
orders
| id | customer_id | amount |
|---|---|---|
| 1 | 7 | 100 |
| 2 | 8 | 250 |
| 3 | 7 | 200 |
| 4 | 9 | 300 |
returns
| customer_id | spent |
|---|---|
| 7 | 300 |
Constraints
- 1 to 14 orders
Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.
More SQL problems
- Bought and SoldEasy
- Busy SymbolsEasy
- Buyers per ProductEasy
- Customers Without OrdersEasy
- Low and HighEasy
- Net PositionEasy
- Orders With NamesEasy
- Pay With BonusEasy