所以,继续另一个问题......
我已经合并,哪个任务是从只能表示实体之间的 1-1 连接(PROJECT)的现有表和可以表示 N-1 连接(工作者)的表创建联结表行,联结表是(PROJECT-工人),每个项目都应该有一个专门的领导,每个工人都应该有一个项目,但现在我应该有一个 nn 连接......这个合并可以完成这项工作:
但不幸的是,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');