Customer leaderboard: name and total_spent (sum of quantity × unit_price across all their order_items), for customers who have ordered, most spent first. Columns: name, total_spent.
Customer leaderboard: name and total_spent (sum of quantity × unit_price across all their order_items), for customers who have ordered, most spent first. Columns: name, total_spent.
Answer
SELECT c.name, SUM(oi.quantity * oi.unit_price) AS total_spent FROM customers c JOIN orders o ON o.customer_id = c.id JOIN order_items oi ON oi.order_id = o.id GROUP BY c.name ORDER BY total_spent DESC;