基本语法:
update 表名
set 字段=case when 条件1 then 值1
when 条件2 then 值2
end
例子:
UPDATE staff
SET position =
CASE
WHEN position_level = 1 THEN
3
WHEN position_level = 2 THEN
25
WHEN position_level = 3 THEN
26
WHEN position_level = 4 THEN
27
END
再附加其他固定条件,后面再接where就行了:
UPDATE staff
SET position =
CASE
WHEN position_level = 1 THEN
3
WHEN position_level = 2 THEN
25
WHEN position_level = 3 THEN
26
WHEN position_level = 4 THEN
27
END
WHERE
role = 6