mysql 使用多列组合在单个查询中更新SQL多行值

bvn4nwqk  于 2023-02-03  发布在  Mysql
关注(0)|答案(1)|浏览(129)

enter image description here
我有一个包含这些数据的表,在做了一些操作后,我想根据两列值code和id将标志值从0更新为1

update table set flag = 1 where code = 'ABC' and id = 10000

update table set flag = 1 where code = 'DEF' and id = 10001

update table set flag = 1 where code = 'GHI' and id = 10002

update table set flag = 1 where code = 'ABC' and id = 10001

我可以用foreach这样做,但是我想用单个查询来更新,我该怎么做呢?

qjp7pelc

qjp7pelc1#

这个应该可以
UPDATE table SET flat = 1 WHERE (code = 'ABC' and id = 10000) OR (code = 'DEF' and id = 10001) OR (code = 'GHI' and id = 10002)

相关问题