有如下需求:
根据B表的b字段更新A表的a字段,关联条件B.id=A.id。
当B表的b字段>0,a字段更新为1,否则更新为-1。
语句如下:
update A t
inner join (select id, case when b>=0 then 1 else -1 end b from B)tt
set t.a = tt.b
where t.id = tt.id
有如下需求:
根据B表的b字段更新A表的a字段,关联条件B.id=A.id。
当B表的b字段>0,a字段更新为1,否则更新为-1。
语句如下:
update A t
inner join (select id, case when b>=0 then 1 else -1 end b from B)tt
set t.a = tt.b
where t.id = tt.id