SQL 替换语句中的内部查询

SQL Inner Query In Replace Statement

我想用其他内容替换列字段的特定部分。唯一的问题是我尝试过的方法不起作用。我正在使用 HeidiSQL

这是数据库的概述: Database Overview

我想做的是 each user_id 和 field_id 523 我想将 'centraal-zorgportaal.nl/afbeeldingen/' 替换为 '/profiles/(对于此处的每个用户 ID)/'

因此 运行 查询后的最终结果示例如下所示: '/profiles/711/logo.gif',但每个用户都有不同的 logo.gif.

注意:不能post两个以上的链接所以去掉前面的http等。

这是我试过但没有用的查询:

update wp_bp_xprofile_data 
   set value = replace( value,
                        'http://www.centraal-zorgportaal.nl/afbeeldingen/',
                        '/profiles/' + 
                        (select user_id 
                           from wp_bp_xprofile_data 
                          where user_id = @n := @n + 1 n) + 
                        '/') 
  where field_id = 523

(Table 名字是: wp_bp_xprofile_data)

这是我收到的错误信息: Error message:

谁能解释为什么这不起作用、如何解决它以及解决此问题的最佳方法?

在MySQL/MariaDB中,您不能引用正在修改的table。根据您的描述,您似乎想要这样的东西:

update wp_bp_xprofile_data
    set value = replace(value,
                        'http://www.centraal-zorgportaal.nl/afbeeldingen/', 
                        concat('/profiles/', user_id, '/')
                       )
    where field_id = 523;