在MySQL中更新查询错误

时间:2017-03-21 15:38:04

标签: mysql

我希望我能在正确的道路上做一切。我写了一个shell脚本,如果条件匹配,它将运行更新查询。

#!/bin/bash
mysql -u root -pPassword <<rc
use rc;
SELECT *,
       CASE 
         WHEN cutoff_dt IS NULL
       THEN 
         UPDATE rc SET cutoff_dt = '2017-03-21 00:00:00.0'
         ELSE 'NOT NULL'
      END
from rc
WHERE business_date = '2017-03-21 16:50:29.032';
rc

不幸的是,我收到了错误

ERROR 1064 (42000) at line 2: 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 'UPDATE rc SET cutoff_dt = '2017-03-21 00:00:00.0'
         ELSE ' at line 5

最新代码

给出的答案没有帮助!也许我做错了?

#!/bin/bash
mysql -u root -pPassword <<rc
use rc;
SELECT *,
       CASE 
         WHEN cutoff_dt IS NULL
       THEN 
        UPDATE mepslog
        SET cutoff_dt = '2017-03-21 23:57:19'
  WHERE business_date = '2017-03-21 00:00:00.000'
    AND cutoff_dt IS NULL
      END
from rc
WHERE business_date = '2017-03-21 00:00:00.000';
rc

1 个答案:

答案 0 :(得分:4)

您无法混合此类查询。相反,您可以扩展查询的where - 子句。

工作更新如下所示:

UPDATE rc
  SET cutoff_dt = '2017-03-21 00:00:00.0'
  WHERE business_date = '2017-03-21 16:50:29.032'
    AND cutoff_dt IS NULL