我正在尝试使用复合键过滤查询,但是,我不确定如何在where子句中使用复合键过滤查询。 XSiteProductItemId
和MercuryProductItemId
组成了一个标识唯一行的复合键。
这是我的查询:
SELECT VMPOrdersExtract.XSiteProductItemId
, VMPOrdersExtract.MercuryProductItemId
FROM Appraisal.ext.VMPOrders AS VMPOrdersExtract
LEFT JOIN dw.DimAppraisal DimApprasial ON DimApprasial.XsiteProductItemId = VMPOrdersExtract.XSiteProductItemId
AND DimApprasial.MercuryProductItemId = VMPOrdersExtract.MercuryProductItemId
WHERE VMPOrdersExtract.LastSyncDateTime > DimApprasial.LastSyncDateTime
OR (
VMPOrdersExtract.XSiteProductItemId
AND VMPOrdersExtract.MercuryProductItemId
) is null
很明显,我在OR
子句中的WHERE
条件在语法上是错误的。如何仅过滤null
表中不存在的DimAppraisal
组合键记录?
答案 0 :(得分:1)
怎么样
WHERE VMPOrdersExtract.LastSyncDateTime > DimApprasial.LastSyncDateTime
OR (VMPOrdersExtract.XSiteProductItemId IS NULL AND
VMPOrdersExtract.MercuryProductItemId IS NULL);
答案 1 :(得分:1)
也将其添加到答案中;)
SELECT VMPOrdersExtract.XSiteProductItemId, VMPOrdersExtract.MercuryProductItemId
FROM Appraisal.ext.VMPOrders AS VMPOrdersExtract LEFT JOIN dw.DimAppraisal DimApprasial
ON DimApprasial.XsiteProductItemId = VMPOrdersExtract.XSiteProductItemId AND
DimApprasial.MercuryProductItemId = VMPOrdersExtract.MercuryProductItemId WHERE
VMPOrdersExtract.LastSyncDateTime > DimApprasial.LastSyncDateTime OR
(VMPOrdersExtract.XSiteProductItemId is null AND VMPOrdersExtract.MercuryProductItemId is null)