Mysql SQL数据更新查询关于

Mysql SQL数据更新查询关于,mysql,sql,database,Mysql,Sql,Database,我有一个名为testlink的表,它有url和newtarget列 我想使用字符串表达式https://domain1.com/在url列中,并将newtarget列中的所有数据更改为https://domain1.com/search/?q=pull字符串表达式 如此短暂 来自https://domain1.com/topic1 将更改为https://domain1.com/search/?q=topic1在newtarget列中 大约有6000个不同的主题(行)可用 数据库:Mysql/P

我有一个名为testlink的表,它有url和newtarget列

我想使用字符串表达式
https://domain1.com/
在url列中,并将
newtarget
列中的所有数据更改为
https://domain1.com/search/?q=
pull字符串表达式

如此短暂

来自
https://domain1.com/topic1
将更改为
https://domain1.com/search/?q=topic1
newtarget
列中

大约有6000个不同的主题(行)可用

数据库:Mysql/Phpmyadmin。

使用

MySQL REPLACE()将替换在 绳子

REPLACE(str,find\u字符串,REPLACE\u为)


如果要有条件地更改值,可以使用字符串操作:

update t
    set url = concat(left(url, length(url) - length(substring_index(url, '/', -1))), 'q=', substring_index(url, '/', -1))
    where url like 'https://domain1.com/%';
这将使用
子字符串\u index()
获取字符串的最后一部分(在最后一个
/
之后)。它使用
left()


当然,如果您使用的是MySQL 8,那么在实现
更新之前,可以使用
选择
来测试此逻辑,然后使用MySQL 8

就您的示例而言,这应该是可行的:

SELECT REGEXP_REPLACE('https://domain1.com/topic1','(https:\/\/domain1\.com\/)(.+)','$1search/?q=$2')

谢谢,但结果不是我想要的;我希望如此;再次检查,我在
REPLACE(url,'https://domain1.com/“,
但是现在已经修改和测试了,它工作得很好。谢谢,这几乎发生了:我怎么能这样做?你介意帮我编辑查询吗?:(我想这样做。)
SELECT REGEXP_REPLACE('https://domain1.com/topic1','(https:\/\/domain1\.com\/)(.+)','$1search/?q=$2')