所有这些表ERTBatches
,ERTBatchChecks
,ERTClaims
都有一个标识符
可以说标识符是1010.
该标识符必须存在于所有三个表中
我试图找出是否所有三个表中都没有任何标识符
这些是标识符的名称:
ERTBatches."BatchIdentifier"
ERTClaims."ERTBatchNumber"
ERTBatchChecks."BatchIdentifier"
答案 0 :(得分:5)
一种方法是union all
和聚合:
select id
from ((select b.BatchIdentifier as id, 1 as which from ERTBatches b) union all
(select bc.BatchIdentifier as id, 2 as which from ERTBatchChecks bc) union all
(select c.ERTBatchNumber as id, 3 as which from ERTClaims c)
) t
group by id
having count(distinct which) < 3;