gpt4 book ai didi

mysql - 根据另外 2 个表的联接结果插入到一个表中

转载 作者:行者123 更新时间:2023-11-29 06:27:58 24 4
gpt4 key购买 nike

我在 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(而不是INSERT): UPDATE DOCS

 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

关于mysql - 根据另外 2 个表的联接结果插入到一个表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58391336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com