MYSQL 从 select 子查询更新
MYSQL Update from a select subquery
响应栏中的数据为=blahblahblahTYPE=ERRORblahblah
。然后我 运行 下面的查询只针对 'ERROR' 字符串。
SELECT substr(Response, instr(Response, 'ERROR'), 5)
FROM table
WHERE id = 721451
AND Status = 'false'
AND Response LIKE '%<status>Unknown</status>%'
AND date >= curdate();
上面的查询 returns: ERROR
.
我基本上想在不编辑其余数据的情况下将 ERROR
更新为 SUCCESS
。
下面的查询是否有效?有更好的方法吗?
UPDATE table
SET Response = 'SUCCESS'
WHERE (
SELECT substr(Response, instr(Response, 'ERROR'), 5)
FROM table
WHERE id = 721451
AND Status = 'false'
AND Response LIKE '%<status>Unknown</status>%'
AND date >= curdate()
);
提前感谢您的帮助!
UPDATE table
SET Response = REPLACE(Response, 'ERROR', 'SUCCESS')
WHERE id = 721451
AND Status = 'false'
AND Response LIKE '%<status>Unknown</status>%'
AND date >= curdate();
参考https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace
响应栏中的数据为=blahblahblahTYPE=ERRORblahblah
。然后我 运行 下面的查询只针对 'ERROR' 字符串。
SELECT substr(Response, instr(Response, 'ERROR'), 5)
FROM table
WHERE id = 721451
AND Status = 'false'
AND Response LIKE '%<status>Unknown</status>%'
AND date >= curdate();
上面的查询 returns: ERROR
.
我基本上想在不编辑其余数据的情况下将 ERROR
更新为 SUCCESS
。
下面的查询是否有效?有更好的方法吗?
UPDATE table
SET Response = 'SUCCESS'
WHERE (
SELECT substr(Response, instr(Response, 'ERROR'), 5)
FROM table
WHERE id = 721451
AND Status = 'false'
AND Response LIKE '%<status>Unknown</status>%'
AND date >= curdate()
);
提前感谢您的帮助!
UPDATE table
SET Response = REPLACE(Response, 'ERROR', 'SUCCESS')
WHERE id = 721451
AND Status = 'false'
AND Response LIKE '%<status>Unknown</status>%'
AND date >= curdate();
参考https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace