gpt4 book ai didi

sql - 合并 SQL 多个插入语句不是一个选项

转载 作者:行者123 更新时间:2023-12-04 20:51:58 25 4
gpt4 key购买 nike

那么,另一个问题的延续......

我合并了哪个任务是从一个只能表示实体(项目)之间的 1-1 连接的现有表和一个可以表示 N-1 连接器(工作人员)的表中创建联结表行,联结表是(PROJECT-WORKER),每个项目都应该有一个专门的领导者,每个 worker 都应该有一个项目,但现在我应该有一个 n-n 连接......这个合并可以完成这项工作:

但不幸的是,multiple matched then insert 分支不是 sql 中的“功能”,我该如何解决这个问题。原始查询---)

MERGE INTO WORKERPROJECT TARGET
USING (SELECT distinct
w.worker_id,
w.worker_type,
w.project_id worker_project_id,
p.project_id project_project_id,
p.dedicated_project_leader,
p.dedicated_lead_developer,
p.dedicated_lead_consultant,
p.dedicated_supervisor
from WORKER w
join PROJECT p on w.project_id = p.project_id
) SOURCE
ON (SOURCE.worker_type is null)
WHEN NOT MATCHED THEN INSERT (TARGET.FK_WORKER_ID, TARGET.FK_PROJECT_ID,TARGET.IS_ACTIVE,POSITION)
VALUES (SOURCE.WORKER_ID,SOURCE.worker_project_id,'ACTIVE',SOURCE.worker_type);
WHEN NOT MATCHED THEN INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION)
VALUES (SOURCE.dedicated_project_leader,SOURCE.project_project_id,'ACTIVE','PROJECTVEZETŐ');
WHEN NOT MATCHED THEN INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION)
INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION) VALUES (SOURCE.dedicated_lead_developer,SOURCE.project_project_id,'ACTIVE','FEJLESZTŐVEZETŐ');
WHEN NOT MATCHED THEN INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION)
INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION) VALUES (SOURCE.dedicated_lead_consultant,SOURCE.project_project_id,'ACTIVE','KONZULENSVEZETŐ');
WHEN NOT MATCHED THEN INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION)
INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION) VALUES (SOURCE.dedicated_supervisor,SOURCE.project_project_id,'ACTIVE','SUPERVISOR');

最佳答案

关于sql - 合并 SQL 多个插入语句不是一个选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14455925/

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