gpt4 book ai didi

MySQL 根据值更新不同的字段

转载 作者:行者123 更新时间:2023-11-29 13:39:30 25 4
gpt4 key购买 nike

我似乎无法让以下 SQL 代码运行:

    UPDATE ip_port
SET
enabled = (case when fails > 5 then enabled = 0 else enabled end),
fails = (case when fails < 5 then fails = fails + 1 else fails end)
WHERE
proxy LIKE '%1.2.3.4:8080%'

基本上我试图让代码设置 enabled = 0如果fails > 5 ,或者如果 fails < 5然后失败加1。

查询的第一部分的工作原理是,如果失败为 6,则将启用设置为 0,但失败时的增量不起作用

最佳答案

UPDATE ip_port
SET enabled = case when fails > 5
then 0
else enabled
end,
fails = case when fails < 5
then fails + 1
else fails
end
WHERE proxy LIKE '%1.2.3.4:8080%'

关于MySQL 根据值更新不同的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18280461/

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