I’m working on Unit 2 in SQL From Scratch, with the following information and question:
The payments table has the following columns: id, user_id, amount, status, pay_date.
Find all the users that have successfully paid Codeflix and their total payments.
Sort them by their total payments (from high to low).
Use SUM(), GROUP BY, and ORDER BY.
The correct answer is:
SELECT user_id, SUM(amount)
FROM payments
WHERE status = ‘paid’
GROUP BY user_id
ORDER BY SUM(amount) DESC;
I couldn’t understand why I was getting all the information it was asking for, yet it was marking it as wrong with the syntax below:
SELECT user_id, SUM(amount), COUNT(*)
FROM payments
WHERE status = ‘paid’
GROUP BY user_id
ORDER BY SUM(amount) DESC;
Why is it that when I additionally use COUNT(*) it marks it as incorrect? As far as I’m aware it looked like the results were the exact same, with the exception of an additional column with more information. In previous problems I’ve created more information than was asked for and was marked correct.