我一直在尝试做的是检测Table1列ADRES`house#240 st。#76 Cantt。road Chicago包含在查找表的错误列中存在的所有值,应将其替换为正确的列值。
表格1:
Username | Adres Jhon | house# 240 st. # 76 Cantt. road Chicago
查找表:
WRONG | Right house# HNO
例如:house# 240 st. # 76 Cantt. road Chicago((房屋号错误,因此应将其替换为HNO)并更新Table1并将地址设置为
house# 240 st. # 76 Cantt. road Chicago
Table1
Jhon | HNO 240 st. # 76 Cantt. road Chicago
如果您想更新字段,
UPDATE table1 a CROSS JOIN lookup b SET a.ADRES = REPLACE(a.ADRES, b.`WRONG`, b.`RIGHT`) WHERE a.ADRES LIKE CONCAT('%', b.`WRONG`, '%')
但是,如果您只想投影替换后的值,
SELECT a.Username, REPLACE(a.ADRES, b.`WRONG`, b.`RIGHT`) FROM table1 a CROSS JOIN lookup b WHERE a.ADRES LIKE CONCAT('%', b.`WRONG`, '%')