gpt4 book ai didi

sql - 根据列的当前值更新列

转载 作者:行者123 更新时间:2023-11-29 12:44:34 24 4
gpt4 key购买 nike

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

比如我有 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);

关于sql - 根据列的当前值更新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31785093/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com