update table set 状态=1 WHERE (种类='火车' and 编号='123') OR(种类='汽车' and 编号='458') OR(种类='导弹' and 编号='1578')
updata table set 状态=case when 种类=‘火车’ and 编号=‘123’ then 1 when 种类=‘汽车’ and 编号=‘458’ then 1 when 种类=‘导弹’ and 编号=‘1578’ then 0 else 状态 end 又如何
天啊,然道你想要始终有三条受影响,不管符不符合?update table set 状态=case when 种类='火车' and 编号='123' then 1 when 种类='汽车' and 编号='458' then 1 when 种类='导弹' and 编号='1578' then 1 else 状态 end WHERE 编号 IN('123','458','1578')
updata table set 状态=case when 种类='火车' and 编号='123’ then 1 when 种类='汽车' and 编号='458’ then 1 when 种类='导弹' and 编号='1578’ then 1 else 状态 end where 种类='火车' and 编号='123’ or 种类='汽车' and 编号='458’ or 种类='导弹' and 编号='1578’
2楼的sql 不行吗?试试这个更灵活一些update table set 状态=b.状态 from table a join ( select '火车' 种类,'123’ 编号,1 状态 union all select '汽车' 种类,'458’ 编号,1 状态 union all select '导弹' 种类,'11578’ 编号,1 状态) b on a.种类=b.种类 and a.编号=b.编号
不好意思,引号变全角了update table set 状态=b.状态 from table a join ( select '火车' 种类,'123' 编号,1 状态 union all select '汽车' 种类,'458' 编号,1 状态 union all select '导弹' 种类,'11578' 编号,1 状态) b on a.种类=b.种类 and a.编号=b.编号
set 状态=1
WHERE (种类='火车' and 编号='123')
OR(种类='汽车' and 编号='458')
OR(种类='导弹' and 编号='1578')
又如何
set 状态=case when 种类='火车' and 编号='123' then 1
when 种类='汽车' and 编号='458' then 1
when 种类='导弹' and 编号='1578' then 1
else 状态
end
WHERE 编号 IN('123','458','1578')
where 种类='火车' and 编号='123’ or 种类='汽车' and 编号='458’ or 种类='导弹' and 编号='1578’
from table a join (
select '火车' 种类,'123’ 编号,1 状态
union all
select '汽车' 种类,'458’ 编号,1 状态
union all
select '导弹' 种类,'11578’ 编号,1 状态) b on a.种类=b.种类 and a.编号=b.编号
不好意思,引号变全角了update table set 状态=b.状态
from table a join (
select '火车' 种类,'123' 编号,1 状态
union all
select '汽车' 种类,'458' 编号,1 状态
union all
select '导弹' 种类,'11578' 编号,1 状态) b on a.种类=b.种类 and a.编号=b.编号