有谁知道为什么以下 2 个查询的结果与第 3 个查询的结果不相加?
SELECT COUNT(leadID) FROM leads
WHERE makeID NOT IN (SELECT uploadDataMapID FROM DG_App.dbo.uploadData WHERE uploadID = 3 AND uploadRowID = 1)
AND modelID NOT IN (SELECT uploadDataMapID FROM DG_App.dbo.uploadData WHERE uploadID = 3 AND uploadRowID = 2)
SELECT COUNT(leadID) FROM Leads
WHERE makeID IN (SELECT uploadDataMapID FROM DG_App.dbo.uploadData WHERE uploadID = 3 AND uploadRowID = 1)
OR modelID IN (SELECT uploadDataMapID FROM DG_App.dbo.uploadData WHERE uploadID = 3 AND uploadRowID = 2)
SELECT COUNT(leadID) FROM Leads
第一个查询是我需要的计数。第二个是根据 DG_App.dbo.uploadData 表的内容告诉用户有多少条记录被抑制。第三个查询只是对所有记录的直接计数。
当我运行这些查询 1 的结果 + 查询 2 的结果时,出现的记录比整个表的计数少约 46K。我玩过用 () 对 WHERE 语句进行分组,但这根本没有改变计数。
这是 MSSQL 服务器 2012。
对此的任何输入都会很棒。
谢谢