gpt4 book ai didi

MySql - 更新/案例

转载 作者:行者123 更新时间:2023-11-29 02:17:54 26 4
gpt4 key购买 nike

我有一个表测试

TestNumber (int primary key)
InactiveBitwise (int)

我执行以下命令:

UPDATE tests SET CASE
WHEN TestNumber = 2 THEN InactiveBitwise = (InactiveBitwise | 4)
WHEN TestNumber = 3 THEN InactiveBitwise = (InactiveBitwise | 8)
END WHERE TestNumber IN (2, 3)

但它给出了错误

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE WHEN TestNumber = 2 THEN InactiveBitwise = (InactiveBitwise |'

TestNumber = 2 和 3 都存在,因为我之前通过调用数据库获得了它们。

有谁知道它不喜欢什么?

最佳答案

您需要指定要更改的列的值,大小写将仅确定返回值:

UPDATE tests SET InactiveBitwise = CASE
WHEN TestNumber = 2 THEN (InactiveBitwise | 4)
WHEN TestNumber = 3 THEN (InactiveBitwise | 8)
END
WHERE TestNumber IN (2, 3)

关于MySql - 更新/案例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36651079/

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