Screen Link:
My Code:
WITH
india AS
(
SELECT * FROM customer
WHERE country = "India"
),
total_purchase AS
(
SELECT c.first_name, c.last_name, c.customer_id,
SUM(i.total) as purchase
FROM customer c
INNER JOIN invoice i
ON c.customer_id= i.customer_id
GROUP BY i.customer_id
)
SELECT p.first_name || ' '||p.last_name AS customer_name,
p.purchase as total_purchase
FROM india i
INNER JOIN total_purchase p
on i.customer_id= p.customer_id
ORDER BY 1
;
What I expected to happen: Since results are the same, this should have worked
What actually happened: Answer did not get accepted
The value for result doesn't look right.
My question is, does my answer work? Agreed, there was no need for first and last name in second subquery and the inner join wasn’t needed in it either.