I'm doing SQL class on Khan Academy and got stuck somewhere in the JOIN query section.
- customers table with id(pk),name, email
- Orders table with id(pk),customer_id, item, price
Question: Create a query that will result in one row per each customer, with their name, email, and total amount of money they've spent on orders. Sort the rows according to the total money spent, from the most spent to the least spent.
My code looks like this but it didn't lead me to the next section. It doesn't say wrong either
SELECT sum(orders.price), customers.name, customers.email, orders.price from customers lEFT OUTER JOIN ORDERS ON customers.id = orders.customer_id GROUP BY customers.name order by sum(orders.price) DESC;
Would appreciate an explanation.