Top customer by total spend

Top customer by total spend

Medium SQL DQL 25 views
Explanation Complexity

Problem Statement

From Orders(customer_id, total_amount), find the customer who spent the most overall. First do SUM per customer, then pick the highest one.

Input Format

SQL query

Output Format

Result set

Example

Orders(customer_id, total_amount)
Top customer row

Constraints

Think: GROUP BY customer_id then ORDER BY SUM desc

Input / Output Format

Input Format
SQL query
Output Format
Result set
Constraints
Think: GROUP BY customer_id then ORDER BY SUM desc

Examples

Input:
Orders(customer_id, total_amount)
Output:
Top customer row

Example Solution (Public)

SQL
SELECT customer_id, SUM(total_amount) AS spend FROM Orders GROUP BY customer_id ORDER BY spend DESC LIMIT 1;

Official Solution Code

SELECT customer_id, SUM(total_amount) AS spend FROM Orders GROUP BY customer_id ORDER BY spend DESC LIMIT 1;
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.