我在 MySQL 中有 3 个表:def_table、spot_table、tag_mapping_spot_table。
def_table
tag_id tag_ja
2010490043 アラバマ・アンド・ガルフ・コースト鉄道
2010680003 american_football、サッカー、スポーツ
2010970036 ノーフォークマツの種
......... ..........
spot_table
spot_id spot_name
1 NULL
2 NULL
3 NULL
... ....
tag_mapping_spot_table
spot_id tag_id
1 2010490043
2 2010680003
3 2010970036
.... .....
我想要做的就是基于列 tag_id 连接“tag_mapping_spot_table”和“def_table”,然后将结果与基于 Spot_id 的“spot_table”连接。我想将结果从列 tag_ja 放入列 Spot_name
就像是
insert into spot(spot_name) where spot_id = b.spot_id
(select a.tag_ja,b.spot_id from def_table a join tag_mapping_spot b
on a.tag_id = b.tag_id
这是我想要在 spot_table 中得到的结果
spot_id spot_name
1 アラバマ・アンド・ガルフ・コースト鉄道
2 american_football、サッカー、スポーツ
3 ノーフォークマツの種
你需要一个UPDATE
(not INSERT
):
更新文档 https://dev.mysql.com/doc/refman/8.0/en/update.html
UPDATE spot_table ST
INNER JOIN tag_mapping_spot_table c ON c.spot_id = ST.spot_id
INNER JOIN def_table b ON b.tag_id = c.tag_id
SET ST.spot_name = b.tag_ja
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)