homework 2
1 changed files with 7 additions and 0 deletions
homework-2.sql ADDED
View File
| @@ -0,0 +1,7 @@ | ||
| 1 | +-- Homework 2 | |
| 2 | +-- Total per customer, only customers who spent more than 100 | |
| 3 | +SELECT c.name, SUM(o.total) AS spent | |
| 4 | +FROM customers c JOIN orders o ON o.customer_id = c.id | |
| 5 | +GROUP BY c.id | |
| 6 | +HAVING spent > 100 | |
| 7 | +ORDER BY spent DESC; | |