oracle怎样查出表中重复列的数据?
1、查出表中重复列的数据:
select a,count(*) from table group by a having count(*)>1
2、查重复次数最多的列:
select a,num from (
select a,count(*) num from table group by a having count(*)>1
)
order by num desc
此外,还有
1、查询一个表中所有字段都相同的记录
比如现在有一人员表 (表名:peosons)
若想将姓名、编号、住址这三个字段完全相同的记录查询出来:
select p1.* from persons p1,persons p2 where p1.name=p2.name and p1.id = p2.id and p1.address=p2.address group by p1.name,p1.id,p1.address having count(*) >1;
或者:
select p1.* from persons p1,persons p2 where p1.name=p2.name
and p1.id=p2.id and p1.address=p2.address and p1.rowid<>p2.rowid;
或者:(下面这条语句执行效率更高)
select * from (select p.*,row_number() over (partition by name,
id,address order by name) rn from persons p) where rn>1;
2、 查询一个表中某字段相同的记录
语法:select p1.* from 表名 p1,(select 字段 from 表名 group by 字段 having count(*)>1) p2 where p1.字段=p2.字段;
select p1.* from persons p1,(select address from persons group by address having count(*)>1) p2
where p1.address=p2.address;
3、查询一个表中某字段相同的记录,其它字段不用查询出来
select name,count(*) from persons group by name having count(*) >1;