Skip to content

Subtract values from the same Column in sql? [closed]

Here is my table named records

SELECT SUM(CASE isDeposited WHEN 0 THEN amount WHEN 1 THEN -amount END) AS total
FROM records WHERE memberID = 3;

That’s my code. I’ve tried it and it works but didn’t give me the right result. memberID 3 has a total of 250 – 50 withdraw, which is 200 but it gives me the result of 150.



You have a problem in the calculation, (4 * 50) - 50 = 150.

User contributions licensed under: CC BY-SA
6 People found this is helpful