按照条件update 字段
比如有这种场景
用户消耗分数,有两个字段 标记分数 一个是每日的免费分数 free_score
另一个是积累分数 total_score
如果 free_score > 0 , 优先使用 free_score
如果 free_score = 0,则使用 total_score
更新语句如下
update card_integral t
set
t.total_score = if(t.free_score = 0 and t.total_score > 0,t.total_score - 1,t.total_score) ,
t.free_score = if(t.free_score > 0 , t.free_score - 1,t.free_score)
where t.id = 1
set 两个 字段的顺序不能颠倒,
否则 会出现 修改了 free_score 为0 后 , 又去 修改 total_score 的bug