如何删除PostgreSQL请求中的重复项?

时间:2019-07-02 10:53:11

标签: postgresql

select distinct on (ipo.cadastre_number) ipo.cadastre_number, ipo.ao_1_formalname, ipo.spec_note_invalid_exam_card, ipo.spec_note_factal_absent, ipo.spec_note_additional_notes, ipo1.spec_note_invalid_exam_card as duplicate_spec_note_invalid_exam_card,
ipo1.spec_note_factal_absent as duplicate_spec_note_factal_absent, ipo1.spec_note_additional_notes as duplicate_spec_note_additional_notes,

case
when ipo.cadastre_number is null then cp.real_cadastre_number
else ipo.cadastre_number
end as duplicate_cadastre_number,

case
when ipo1.cadastre_number is null then cp1.real_cadastre_number
else ipo1.cadastre_number
end as original_cadastre_number

from analytics.import_property_objects_copy ipo

left join protected.cadastral_properties cp
on ipo.exam_card = cp.id::text

left join protected.cadastral_properties cp1
on ipo.duplicate_exam_card_number = cp1.id::text

left join analytics.import_property_objects_copy ipo1
on ipo1.exam_card = cp1.id::text

where ipo.duplicate_exam_card_number is not null
and ipo.cadastre_number not in (select fr.cadastre_number from service.from_rosreestr fr)
and (ipo.all_correct ilike '%ублирующий%' or ipo.all_correct ilike '%ыявленный%')
order by 

结果,我得到了很多重复(通过case操作) 我尝试了DISTINCT ON,但没有成功。 屏幕截图:https://imgur.com/Iz38EmP

0 个答案:

没有答案