我正在尝试根据“货币”表中每个记录的“货币代码”来更新多条记录的余额,这会产生一些影响:
UPDATE Currency
SET `Balance` = `Balance` - NEW.AmountOut WHERE `CurrencyCode` = ?,
`Balance` = `Balance` + NEW.AmountIn - NEW.Commission WHERE `CurrencyCode` = ?;
我确定您了解逻辑,但我的实现似乎有些混乱。我要去哪里错了,怎么解决?
答案 0 :(得分:1)
使用case when
示例
update Currency
set Balance= case when CurrencyCode= ? then `Balance` - NEW.AmountOut
else `Balance` + NEW.AmountIn - NEW.Commission end