0

我想显示一个数据集中不在另一个数据集中的记录。

这是更大数据集的代码:

select distinct facil_identifier, facil_addr_line1,
trim(facil_city) as facil_city, facil_zip
from xx.tb1 f
where facil_identifier is not null

我想在第一个(较大的)数据集中找到不在较小数据集中的记录。

这是较小数据集的代码:

select distinct facil_identifier, facil_addr_line1,
facil_zip
from xx.tb1 f
where facil_identifier is not null

这是我的尝试:

select distinct facil_identifier, facil_addr_line1,
facil_zip
from xx.tb1 f
where facil_identifier is not null
and facil_identifier not in
(select facil_identifier
from 
    (select distinct facil_identifier, facil_addr_line1,
    trim(facil_city) as facil_city, facil_zip
    from xx.tb1 f2
    where facil_identifier is not null) as city
where city.facil_identifier = f.facil_identifier)
order by facil_addr_line1

此代码具有巨大的成本。每组少于 3000 条记录。

4

1 回答 1

0

我不是 postgres SQL 方面的专家,但应该这样做(或者至少让你接近)

select distinct f2.facil_identifier, f2.facil_addr_line1,
trim(f2.facil_city) as facil_city, f2.facil_zip
from import.facil_xx_20131016 f2
left join import.facil_xx_20131016 f on f2.facil_identifier = f.facil_identifier
where f2.facil_identifier is not null
and f.facil_identifier is null
于 2013-10-18T21:03:28.090 回答