根据列的当前值更新列

Update a column based on its current value

有什么方法可以通过一次查询根据当前值更改字段值吗?

就像我有 tbl.team,如果它的值为 = 1,请将其更改为 2。反之亦然,tbl.team = 2 => 1.

您可以使用 case 表达式有条件地更新列:

update the_table
  set team = case 
                when team = 1 then 2
                else 1
             end
where team in (1,2);