Top Customers by Spend

Top Customers by Spend

Easy Programming Interview DBMS 24 views
Explanation Complexity

Problem Statement

Tables: Orders(order_id, customer_id, total_amount, created_at). Return customer_id and total spend, sorted by spend desc.

Input Format

SQL tables are described in the question.

Output Format

Write the SQL query.

Input / Output Format

Input Format
SQL tables are described in the question.
Output Format
Write the SQL query.

Example Solution (Public)

Programming Interview
SELECT customer_id, SUM(total_amount) AS total_spend
FROM Orders
GROUP BY customer_id
ORDER BY total_spend DESC;

Official Solution Code

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

                                        
Please login to submit solutions.