Used a different approach, got the same answer. This answer was not accepted. Please provide your feedback

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.

2 Likes

Hello @nandy.arijit, Welcome back to the community. Your code looks amazing.

Here is what is causing the error, the final column should be total_purchases

  • total_purchases - The total amount spent on purchases by that customer.

If you correct that everything will be fine.

3 Likes

Thanks Victor! Good callout, my mistake. Appreciate your quick response!

1 Like