Top customer by total spend
SQL
Medium
3 views
Problem Description
From Orders(customer_id, total_amount), find the customer who spent the most overall. First do SUM per customer, then pick the highest one.
Sample Test Case
Input:
Orders(customer_id, total_amount)
Constraints
Think: GROUP BY customer_id then ORDER BY SUM desc
Official Solution
SELECT customer_id, SUM(total_amount) AS spend FROM Orders GROUP BY customer_id ORDER BY spend DESC LIMIT 1;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!