三种sql语句找出表中重复记录写法
本文导语: 一,创建测试数据 代码示例: create table test_0210(id number,name varchar2(32),age number); insert into test_0210 values(1,'abc',32); insert into test_0210 values(2,'def',33); insert into test_0210 values(3,'def',45); commit; select * from test_0210; SQL> select * from te...
一,创建测试数据
create table test_0210(id number,name varchar2(32),age number);
insert into test_0210 values(1,'abc',32);
insert into test_0210 values(2,'def',33);
insert into test_0210 values(3,'def',45);
commit;
select * from test_0210;
SQL> select * from test_0210;
ID NAME AGE
---------- -------------------------------- ----------
1 abc 32
2 def 33
3 def 45
第一种写法sql:
SQL> select a.*
2 from test_0210 a,test_0210 b
3 where a.id b.id and a.name = b.name ;
ID NAME AGE
---------- -------------------------------- ----------
3 def 45
2 def 33
第二种写法sql:
SQL> select a.* from test_0210 a,(select name,count(*) from test_0210 b group by name having count(*)>1) b
2 where a.name=b.name;
ID NAME AGE
---------- -------------------------------- ----------
2 def 33
3 def 45
第三种写法sql 利用分析函数
SQL> select id,name,age
2 from (select id,name,count(name) over(partition by name) as rn,age
3 from test_0210)
4 where rn > 1
5 ;
ID NAME AGE
---------- -------------------------------- ----------
2 def 33
3 def 45
- sql重复记录查询与删除实例
- sql server删除表中重复记录
- 一条sql语句删除表中重复记录
- sql查询重复记录的方法举例
- sql server一条语句删除表中重复记录
- 删除SQL重复记录的方法介绍
- sql server 查询重复记录的多种方法