gpt4 book ai didi

MYSQL 如果不存在则批量插入如果存在则更新

转载 作者:行者123 更新时间:2023-11-29 02:14:31 32 4
gpt4 key购买 nike

我正在寻找类似的东西-

insert into table1(a, b, c)
select col1 as d, col2 as e, col3 as f from table2
on duplicate key update b = e, c = f;

注意 - 这里的 table1.a 是唯一的键。

我收到错误消息 - 未知列名称“e”。

是否有将“On duplicate key”与“Insert into Select”语句一起使用的解决方案?

谢谢!

最佳答案

使用别名引起的困惑

insert into table1(a, b, c)
select col1 as d, col2 as e, col3 as f from table2
on duplicate key update b = table2.col2, c = table2.col3;

关于MYSQL 如果不存在则批量插入如果存在则更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42297085/

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