select*from table_name where column_name in(select column_name from table_name groupby column_name havingcount(column_name)>1) orderby column_name;
多个条件
1 2 3 4 5 6 7 8 9 10
select*from table_name as t1 where ( selectcount(*) from table_name t2 where t2.column_name_1=t1.column_name_1 and t2.column_name_2=t1.column_name_2 and t2.column_name_3=t1.column_name_3 and t2.column_name_4=t1.column_name_4 )>1;
删除重复只保留一个
表名: table_name
查询列: column_name
单个条件
1 2 3
deletefrom table_name where column_name in (select column_name from table_name groupby column_name havingcount(column_name) >1) and ctid notin (selectmin(ctid) from table_name groupby column_name havingcount(column_name)>1);
多个条件
1 2 3 4 5 6 7 8 9
deletefrom table_name where (column_name1,column_name2,column_name3) in (select column_name1,column_name2,column_name3 from table_name groupby column_name1,column_name2,column_name3 havingcount(*) >1) and ctid notin (selectmin(ctid) from table_name groupby column_name1,column_name2,column_name3 havingcount(*)>1);