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));
根据某个字段分组删除重复数据,只保留日期最大的一条,建议使用窗口函数效率更高
标签:deltest,postgresql,删除,重复,ctid,where,id,select 来源: https://www.cnblogs.com/zhangfx01/p/14872380.html