I just solved 190-8. I’ve been forcing myself to write the answers completely off-platform on Notepad++, then bringing them back and running them. I want to learn without relying too much on iterative testing.
Anyway, so I solve this one on the first try, and I decided to check the answer to see any differences, and I see it took a much longer and complex road. I know the missions are open-ended and what matters is the end-result, but I fear that maybe there’s something I’m missing.
My question is specifically about this temporary view in the answer:
country_best_customer AS ( SELECT cmp.country, cmp.max_purchase, ( SELECT ccp.customer_id FROM customer_country_purchases ccp WHERE ccp.country = cmp.country AND cmp.max_purchase = ccp.total_purchases ) customer_id FROM country_max_purchase cmp )
Why is it necessary? I feel the second temporary view that calculates the MAX spend from each country already works because it gives you the customer_name associated with it if you add it to the SELECT statement.