替换在与其他列中的名称匹配的列中找到的所有名称

时间:2019-07-18 11:59:10

标签: mysql

我有两个表,其布局如下:

表A

|---------------------|-------------------------------------------------------------------------------------------|
|      name           |     info                                                                                  |
|---------------------|-------------------------------------------------------------------------------------------|
|          1          |  Dark Magician is a normal monster. It can be used with cards such as Dark Magician Girl. |
|          2          |  Blue-Eyes White Dragon is a normal dragon monster. Dragon Capture Jar counters this card.|
|---------------------|-------------------------------------------------------------------------------------------|

表B

|--------------------- |
|      name            | 
|----------------------|
|Dark Magician         |
|Dark Magician Girl    |
|Blue-Eyes White Dragon|
|Dragon Capture Jar    |
|----------------------|

所以我正在将tablea.infotableb.name进行比较,如果找到匹配项,我想用<a href="/name">name</a>替换匹配的名称

对于表A ,我的预期输出将是这样的:

|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|      name           |     info                                                                                                                                                          |
|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|          1          |  <a href="/Dark Magician">Dark Magician</a> is a normal monster. It can be used with cards such as <a href="/Dark Magician Girl">Dark Magician Girl</a>.          |
|          2          |  <a href="/Blue-Eyes White Dragon">Blue-Eyes White Dragon</a> is a normal dragon monster. <a href="/Dragon Capture Jar">Dragon Capture Jar</a> counters this card.|
|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|

我不确定这样做的最佳途径是什么。

我认为我将tableb.nametableb.info进行了比较,但是我在更新部分方面感到苦恼。 我在想更换吗?所以像这样:

REPLACE(ta.info,'%Dark Magician%','%<a href="/Dark Magician">Dark Magician</a>%')

最好的解决办法的建议。

0 个答案:

没有答案