c.first_name || " " || c.last_name customer_name,
WHEN sum(i.total) < 40 THEN 'small spender'
WHEN sum(i.total) > 100 THEN 'big spender'
FROM invoice i
INNER JOIN customer c ON i.customer_id = c.customer_id
GROUP BY 1 ORDER BY 1;
In the solution, why do we sum the total? Doesn’t total already mean it is a sum, or are there multiple purchases and invoices?
Total is a line on an
invoice. So every
receipt / invoice has
total for every transaction. However, a customer can buy more than once
(therefore, we can group by customers). So this is why we have to
total for each customer.
Each customer can purchases multiple times from us which means there can be multiple invoices for a single customer. Each invoice contains the total price for all the tracks purchased by that customer in a single transaction. Since each custumer may make multiple transactions (purchase multiple times), they could have more than one invoice, and as a result, more than one total price. We sum the all the total in all the invoices belonging to a single customer has to find out how much that customer has spent all together so we can figure out kind of spender they are.
Thank you @adewalade and @monorienaghogho, this makes sense now.