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