我有两个表,我希望在这个意义上进行比较,如果circuitId
在两列中相同,那么如果它们是相同的,它应检查CHECKSUM列是否相同没有别的东西在表中插入新记录。如果表中没有circiutId
,它应该添加一个新行。
到目前为止,我有这个,但我不确定如何实现,以便在WHEN MATCHED THEN
的逻辑内部。所以它在里面检查校验和是否相同,从而从那个插入记录?
MERGE INTO ARCHIVE.F1_CIRCUITS n
USING EXTRACT.F1_CIRCUITS o
ON
(n.CIRCUITID= o."circuitId")
WHEN MATCHED THEN
WHEN NOT MATCHED THEN
INSERT VALUES
("circuitId","circuitRef","name","location","country","lat","lng","alt","url", CURRENT_TIMESTAMP, NULL, HASH_MD5("circuitId","circuitRef","name","location","country","lat","lng","alt","url"), 'C', 0)
答案 0 :(得分:0)
我认为insert
就足够了:
INSERT INTO ARCHIVE.F1_CIRCUITS ( . . . )
SELECT . . .
FROM EXTRACT.F1_CIRCUITS o
WHERE NOT EXISTS (SELECT 1
FROM ARCHIVE.F1_CIRCUITS n
WHERE o.circuitid = n.circuitid AND
o.checksum = n.checksum
);
. . .
用于各种列名和表达式。