MySql-Update/Case
我有一张桌子MySql-Update/Case,mysql,sql-update,case-when,Mysql,Sql Update,Case When,我有一张桌子 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 Test
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)