【问题标题】:MySql - Update/CaseMySql - 更新/案例
【发布时间】:2016-08-07 15:48:31
【问题描述】:

我有一张桌子测试

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 都存在,因为我之前通过调用数据库获得了它们。

有人知道它不喜欢什么吗?

【问题讨论】:

    标签: mysql sql-update case-when


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-10-07
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      相关资源
      最近更新 更多