可以找到重复的副本,但是为什么删除不起作用?

时间:2019-10-02 12:30:48

标签: postgresql

我尝试从开源建筑数据库中清除表。

第一步是寻找重复项,因为我使用了

SELECT   COUNT(*) AS nbr_doublon, type_local, date_mutation, valeur_fonciere, adresse_code_voie, adresse_nom_voie, adresse_suffixe, adresse_numero, type_local, surface_reelle_bati
FROM     dvf_2018
WHERE type_local='Dépendance'
GROUP BY type_local, date_mutation, valeur_fonciere, adresse_code_voie, adresse_nom_voie, adresse_suffixe, adresse_numero, type_local, surface_reelle_bati
HAVING   COUNT(*) > 1

enter image description here

好的,可以识别重复项,但是对于任何条目仅保存一个的最佳方法是什么?

尝试

DELETE 
FROM dvf_2018 t1 
USING dvf_2018 t2
WHERE t1.id > t2.id
AND t1.type_local='Dépendance'
AND t2.type_local='Dépendance'
AND t1.date_mutation = t2.date_mutation
AND t1.valeur_fonciere = t2.valeur_fonciere
AND t1.adresse_code_voie = t2.adresse_code_voie
AND t1.adresse_nom_voie = t2.adresse_nom_voie
AND t1.adresse_suffixe = t2.adresse_suffixe
AND t1.adresse_numero = t2.adresse_numero
AND t1.type_local = t2.type_local
AND t1.surface_reelle_bati = t2.surface_reelle_bati

但是删除0行,为什么呢?最好的方法是什么?谢谢

0 个答案:

没有答案