gpt4 book ai didi

sql - 从 select 中插入多行到另一个表中

转载 作者:行者123 更新时间:2023-12-04 16:34:00 26 4
gpt4 key购买 nike

假设我有 `table1(col1,col2,col3),在 col1 和 col3 上插入的值将相同,但在 col2 上插入的值来自选择查询的结果。

我如何编写我的查询,以便我可以一次进行多次插入?
查询应该做什么的示例:

col1  |  col2   | col3

1 val1 0
1 val2 0
1 val3 0

最佳答案

如果我理解正确,你会使用 insert . . .select :

insert into table1(col1, col2, col3)
select 1, col2, 0
from <your other query here>;

关于sql - 从 select 中插入多行到另一个表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31072325/

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