postgresql-删除重复数据保留一条

1.常规删除方法
explain analyse delete from deltest a where a.ctid <> (select min(t.ctid) from deltest t where a.id=t.id);
2.group by删除方法
explain analyse delete from deltest a where a.ctid not in (select min(ctid) from deltest group by id);
3.row_number删除方法
explain analyze delete from deltest a where a.ctid = any(array (select ctid from (select row_number() over (partition by id), ctid from deltest) t where t.row_number > 1));

根据某个字段分组删除重复数据,只保留日期最大的一条,建议使用窗口函数效率更高

上一篇:Greenplum表里的8个隐含字段


下一篇:Photoshop插件--液化--柔光--叠加--脚本开发--PS插件