如何将role = 1
的所有记录更新为2
,将role = 2
的记录更新为值1
?
login | role
----------+------
john | 1
anne | 2
adam | 1
robert | 1
katie | 1
bob | 2
tom | 2
...many records with 1 and 2 values
答案 0 :(得分:4)
UPDATE table
SET role = CASE role
WHEN 1 THEN 2
ELSE 1
END
WHERE role = 1 OR role = 2;
答案 1 :(得分:1)
UPDATE [table]
SET role = CASE role
WHEN 1 THEN 2
ELSE 1
END
WHERE role = 1 OR role = 2;