在 MySQL 中更新查询错误 [英] Update query wrong in MySQL

查看:47
本文介绍了在 MySQL 中更新查询错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm hope I doing everything in the right path. I wrote a shell script, if the condition matched, it will run update query.

#!/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

最新代码

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

The answer given doesn't helped ! Maybe I'm doing wrong ?

#!/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

推荐答案

你不能混合这样的查询.相反,您可以扩展查询的 where-clause.

You cant mix such queries. Instead you would extend the query's where-clause.

工作更新如下所示:

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

这篇关于在 MySQL 中更新查询错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆