添加<条码>EXISTS。 a. 在无关系的情况下检查任何记录的条款:
SELECT Name, CustomerNumber, COUNT(*) As DupeCount
FROM StagingCustomers S
WHERE ManufacturerID=15
AND NOT EXISTS (SELECT 1 from Orders WHERE CustomerID = S.CustomerID)
GROUP BY Name, CustomerNumber
HAVING COUNT(CustomerNumber) > 1
ORDER BY CustomerNumber
http://www.un.org。
删除以下记录的例子。 这将为符合上述标准的每份记录设定<代码>。 为了更明确地回答,你需要回答您的布局和关系。
UPDATE S
SET IsDeleted = 1
FROM StagingCustomers S
WHERE ManufacturerID=15
AND NOT EXISTS (SELECT 1 from Orders WHERE CustomerID = S.CustomerID)
AND CustomerID NOT IN (SELECT CustomerNumber, MIN(CustomerID)
FROM StagingCustomers
GROUP BY CustomerNumber)
GROUP BY Name, CustomerNumber
HAVING COUNT(CustomerNumber) > 1
ORDER BY CustomerNumber