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.

## Advertisement

## Answer

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