gpt4 book ai didi

php - Mysql插入或更新一个表列数据到另一张具有匹配值的表

转载 作者:行者123 更新时间:2023-11-29 11:42:43 25 4
gpt4 key购买 nike

我对 Mysql 有点陌生,我的问题是,如何将 Table_1 列数据更新或插入到 Table_2 列数据,并匹配 中的相关 ID表_1

例如。

          Table_1                       Table_2                      

rand | cpn rand | cpn
1 4 2 0
2 7 3 0
3 2 5 0
4 1 1 0
5 7 4 0

上面提到的表是我的表的当前结构,我的输出应该是这样的,

      Table_2

rand | cpn
2 7
3 2
5 7
1 4
4 1

我想匹配 table_1 中的 ID 并在 table_2 中更新,因此提前致谢:)

最佳答案

这应该有效:

update table2 t2 set cpn = (select cpn from table1 where rand = t2.rand)

关于php - Mysql插入或更新一个表列数据到另一张具有匹配值的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35503432/

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