MySql - Update/Case
MySql - Update/Case
我有一个 table 测试
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)
我有一个 table 测试
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)