Using SUM() with a CASE statement

Viewed 64

I am trying to get the total amount of liability ,using SQL, from a table. I tried to sum the amount if notes equals the text liability. This code that I generated give me an error:

invalid column name 'total_liability'.

I tried to fix it by putting quotes on 'total_liability' after AS, but still get the same error.

SELECT amount,notes,
SUM(CASE         
        WHEN notes = 'liability' THEN SUM(amount)
    END) AS total_liability
FROM expenses
GROUP BY total_liability;
0 Answers
Related