mysql 5.7, mybatis 3.4
i have a table tableA whose id is the pk, outstanding is decimal and status is int.
in my java code, there are following steps(they are in one transaction):
select * from tableA for updateupdate tableA set outstanding = outstanding - #{amount}, status=IF(outstanding = 0, 2, 3) where id=#{id}
what i want is, e.g. :
if outstanding is 10, and the amount is 10, then after run the code above, the outstanding should be 0, and status should be 2(represent full settled); if amount is 5,then after run the code above, the outstanding should be 5, and status should be 3(partial settle).
However, i encounter one time that outstanding = 0, but status = 3, this is incorrect.(in most cases, it works, outstanding = 0, status = 2).
so is there potential problem for update tableA set outstanding = outstanding - #{amount}, status=IF(outstanding = 0, 2, 3) where id=#{id}? if yes, why?