且数据b的b和c都要等于数据c的b和c才能断定为重复。
如何找出这样的数据,并且删除重复的,只保留一条。
或者一张表的字段有100个。如何做?谢谢。
10 个解决方案
#1
--重复数据只显示一条:
select min(id) id,b,c from tb group by b,c
--删除重复数据:
delete from tb where rowid not in (select min(rowid) from tb group by b,c);
#2
能解释下么,数据库我还很生疏。谢谢。
#3
oracle 中rowid(伪列) 用来唯一标示一行记录
上面的语句按 b, c列分组,并找出每组最小的rowid, 然后其它行的数据删除。
#4
delete from 1张表 a
where exists (select 1 from 1张表 where 数据b=a.数据b and 数据c=a.数据c and 数据a<a.数据a)
#5
create table test (id number, name varchar2(40));
insert into test(id,mame) values (1,'huangbiquan');
insert into test(id,mame) values (1,'huangbiquan');
insert into test(id,mame) values (1,'huangbiquan');
insert into test(id,mame) values (2,'xiaoquan');
insert into test(id,mame) values (3,'bishui');
insert into test(id,mame) values (4,'youyouquan');
commit;
查询相同记录
1.select * from test t where t.rowid > (select min(x.rowid) from test x where t.id = x.id);
2.select * from test t where t.rowid <> (select max(x.rowid) from test x where t.id = x.id);
3.select count(*),t.id, t.name from test t group by id,name having count(*) > 1;
查询不相同的记录
1.select * from test t where t.rowid <= (select min(x.rowid) from test x where t.id = x.id);
2.select distinct t.* from test t;
删除重复记录
1.delete from test t where t.rowid > (select min(x.rowid) from test x where t.id = x.id);
2.delete from test t where t.rowid <> (select max(x.rowid) from test x where t.id = x.id);
delete from tt
where rowid in(select rd from(
select rowid rd,row_number()over(partition by 字段 order by rownum)rn
from tt)
where rn <>1)
#6
多条重复的能只剩一条吗
#7
相似的问题csdn有很多解答过的。。
#8
一楼的方法可以
#9
<pre>
</pre>
select * from tb a join(
select repeatColumnA,repeatColumnB,repeatColumnN from tb
group by repeatColumnA,repeatColumnB,repeatColumnN
having count(*)>1
)b on a.repeatColumnA=b.repeatColumnA
and a.repeatColumnB=b.repeatColumnB
and a.repeatColumnN=b.repeatColumnN;
</pre>
#10
应该在多个字段的情况下会有多余记录产生,我测试了下
多个字段指除了重复的2个字段外其它未查询的字段
#1
--重复数据只显示一条:
select min(id) id,b,c from tb group by b,c
--删除重复数据:
delete from tb where rowid not in (select min(rowid) from tb group by b,c);
#2
能解释下么,数据库我还很生疏。谢谢。
#3
oracle 中rowid(伪列) 用来唯一标示一行记录
上面的语句按 b, c列分组,并找出每组最小的rowid, 然后其它行的数据删除。
#4
delete from 1张表 a
where exists (select 1 from 1张表 where 数据b=a.数据b and 数据c=a.数据c and 数据a<a.数据a)
#5
create table test (id number, name varchar2(40));
insert into test(id,mame) values (1,'huangbiquan');
insert into test(id,mame) values (1,'huangbiquan');
insert into test(id,mame) values (1,'huangbiquan');
insert into test(id,mame) values (2,'xiaoquan');
insert into test(id,mame) values (3,'bishui');
insert into test(id,mame) values (4,'youyouquan');
commit;
查询相同记录
1.select * from test t where t.rowid > (select min(x.rowid) from test x where t.id = x.id);
2.select * from test t where t.rowid <> (select max(x.rowid) from test x where t.id = x.id);
3.select count(*),t.id, t.name from test t group by id,name having count(*) > 1;
查询不相同的记录
1.select * from test t where t.rowid <= (select min(x.rowid) from test x where t.id = x.id);
2.select distinct t.* from test t;
删除重复记录
1.delete from test t where t.rowid > (select min(x.rowid) from test x where t.id = x.id);
2.delete from test t where t.rowid <> (select max(x.rowid) from test x where t.id = x.id);
delete from tt
where rowid in(select rd from(
select rowid rd,row_number()over(partition by 字段 order by rownum)rn
from tt)
where rn <>1)
#6
多条重复的能只剩一条吗
#7
相似的问题csdn有很多解答过的。。
#8
一楼的方法可以
#9
<pre>
</pre>
select * from tb a join(
select repeatColumnA,repeatColumnB,repeatColumnN from tb
group by repeatColumnA,repeatColumnB,repeatColumnN
having count(*)>1
)b on a.repeatColumnA=b.repeatColumnA
and a.repeatColumnB=b.repeatColumnB
and a.repeatColumnN=b.repeatColumnN;
</pre>
#10
应该在多个字段的情况下会有多余记录产生,我测试了下
多个字段指除了重复的2个字段外其它未查询的字段