如何过滤 where 子句中的组合键?
How do you filter a composite key in the where clause?
我正在尝试使用复合键过滤查询,但是,我不确定如何在 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
显然我在 WHERE
子句中的 OR
条件在句法上是不正确的。如何仅过滤 null
或 DimAppraisal
table 中不存在的组合键记录?
怎么样
WHERE VMPOrdersExtract.LastSyncDateTime > DimApprasial.LastSyncDateTime
OR (VMPOrdersExtract.XSiteProductItemId IS NULL AND
VMPOrdersExtract.MercuryProductItemId IS NULL);
也将其添加到答案中 ;)
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)
我正在尝试使用复合键过滤查询,但是,我不确定如何在 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
显然我在 WHERE
子句中的 OR
条件在句法上是不正确的。如何仅过滤 null
或 DimAppraisal
table 中不存在的组合键记录?
怎么样
WHERE VMPOrdersExtract.LastSyncDateTime > DimApprasial.LastSyncDateTime
OR (VMPOrdersExtract.XSiteProductItemId IS NULL AND
VMPOrdersExtract.MercuryProductItemId IS NULL);
也将其添加到答案中 ;)
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)