gpt4 book ai didi

sql - 从多个源/表插入

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

我有一个包含这些列的表 FinalTable:

name, lastName, pesel, position, id_operator

我想用其他 2 个表中的值填充我的 FinalTable:

  • AAA - 此表包含姓名、姓氏、姓氏、位置等列
  • BBB - 此表包含列 name、id_operator、pesel

我想在 pesel 列加入 AAABBB

insert into FinalTable (name, lastName, pesel, position, id_operator)
select
name, lastName, pesel, position,
(select id_operator from BBB b where b.pesel = a.pesel)
from
AAA a;

该怎么做?我想将最后一列 id_operator 设置为 BBB 中的值。上面的 SQL 查询不正确。

最佳答案

我会插入一个连接查询:

INSERT INTO FinalTable  (name, lastName, pesel, position, id_operator)
SELECT a.name, a.lastName, a.pesel, a.position, b.id_operator
FROM AAA a
JOIN BBB b ON pesel = a.pesel;

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

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