Hi !
I’m trying to figure out the Challenge : Each Country’s Best Costumer https://app.dataquest.io/m/190/building-and-organizing-complex-queries/8/challenge-each-countrys-best-customer
I found a solution that seems to return an output same as that proposed by DQ , but DQ doesn’t accept my solution , I don’t understand why , maybe the cause is the fact that in some cases some results are truncated (e.g. 39.6 instead of 39.60) , despite the fact i used the round() function. I tried to use the printf() function but it doesn’t solve the issue.
My code is :
WITH list_country AS
(
SELECT
c.country,
c.first_name || " " || c.last_name customer_name,
ROUND(SUM(i.total),2) total_purchased
FROM customer c
LEFT JOIN invoice i ON i.customer_id=c.customer_id
GROUP BY 1,2
ORDER BY 1
)
SELECT country,customer_name,MAX(total_purchased) total_purchased FROM list_country
GROUP BY 1
ORDER BY 1
Any advice ?