我有一个名为'系统'的表有2列'变量'和'值' 以下数据:
我想在1个查询中更新这两个字段。
2个查询是:
UPDATE System SET Value = 'myuser' WHERE Variable = 'Username'
UPDATE System SET Value = 'mypass' WHERE Variable = 'Password'
答案 0 :(得分:4)
UPDATE System
SET Value = (CASE
WHEN Variable = 'Username' THEN 'myuser'
WHEN Variable = 'Password' THEN 'mypass'
END)
WHERE Variable = 'Username' or Variable = 'Password'
答案 1 :(得分:2)
是的,使用他的案例陈述:
UPDATE System
SET Value = (case when Variable = 'UserName' then 'myuser'
when Variable = 'Password' then 'mypass'
else Value
end)
WHERE Variable in ('Username', 'Password');
答案 2 :(得分:0)
UPDATE System
SET Value = case when Variable = 'Username' then 'myuser'
when Variable = 'Password' then 'mypass'
end
WHERE Variable in ('Username', 'Password')
答案 3 :(得分:0)
UPDATE System SET
Value = (case Variable when 'Username' then 'myuser' when 'Password' then 'mypass' end)
WHERE Variable = 'Username' or Variable = 'Password'
答案 4 :(得分:0)
UPDATE System SET `Value` = IF(`Variable`='Username', 'myuser', 'mypassw')
WHERE `Value` IN ('Username', 'Password');