11 months ago
7 lines222 B
-- Homework 2 | |
-- Total per customer, only customers who spent more than 100 | |
SELECT c.name, SUM(o.total) AS spent | |
FROM customers c JOIN orders o ON o.customer_id = c.id | |
GROUP BY c.id | |
HAVING spent > 100 | |
ORDER BY spent DESC; |