可以用这个语句 select * from 表 group by 字段 having count(*)>1;
age tota 23 32 23 34 22 33 23 32 21 32 假设数据时这样的 按照1楼的语句来查找 假设根据age来查找 查找出来的结构会出现age列中数据一样tota列中不一样的数据
那可以改成这样: select * from 表 group by age,tota having count(1)>1;
--可以利用交集来实现 select * from T intersect select * from T
不好意思,上面的sql写错了,我给当成不同的表了,如果就一张表的话,用下面的这个应该可以 因为这里没有环境,你试下这个可以不? select * from (select T.*,rownum rn from T) A where rn/2=0 intersect select * from (select T.*,rownum rn from T) A where rn/2!=0 因为我这里没有环境,你调试一下
--不好意思,运算符写错了,应该是取余 [code=SQL]select * from (select T.*,rownum rn from T) A where rn%2=0 intersect select * from (select T.*,rownum rn from T) A where rn%2=1 --ps:如果报错,告诉下我是什么错,我觉得这个应该可以。 [/code]
我在pl/sql中试了下七楼中的语句 发现不支持取余
create table test as select distinct * from table_duplicate; drop table table_duplicate; rename test to table_duplicate; 最简单,看有没有索引什么的,重新建上索引。
--如果只是查询重复的记录 select age ,tota from table group by age tota having count(1)>1
--如果想要删除重复数据 delete table a where a.rowid in ( select rowid from table b where a.rowid<>b.rowid and a.age= b.age and a.tota = b.tota )
--修正一下删除逻辑 DELETE TABLE a WHERE ROWID NOT IN (SELECT max(ROWID) FROM TABLE b GROUP BY age,tota)
--怎么会不支持呢? select id from test -------------------- 1 2 3 4 5 6select id from test where id%2=1 ------------------------- 1 3 5
--楼主试下这个,minus去掉相同记录 --一个为distinct后的去重结果集,一个为所有结果集,应该可以把重复记录留下来 select * from tab minus select distinct * from tab--如果上面的把重复记录也去掉的话,你就把rowid也搜出来,再去重,肯定没问题了吧 select rowid, tab.* from tab minus select rowid, * from (select distinct tab.* from tab)--如果还还不行,那就只能笨方法了,把所有字段都group by 了
23 32
23 34
22 33
23 32
21 32
假设数据时这样的 按照1楼的语句来查找 假设根据age来查找 查找出来的结构会出现age列中数据一样tota列中不一样的数据
select * from 表 group by age,tota having count(1)>1;
--可以利用交集来实现
select * from T
intersect
select * from T
因为这里没有环境,你试下这个可以不?
select * from (select T.*,rownum rn from T) A where rn/2=0
intersect
select * from (select T.*,rownum rn from T) A where rn/2!=0
因为我这里没有环境,你调试一下
--不好意思,运算符写错了,应该是取余
[code=SQL]select * from (select T.*,rownum rn from T) A where rn%2=0
intersect
select * from (select T.*,rownum rn from T) A where rn%2=1
--ps:如果报错,告诉下我是什么错,我觉得这个应该可以。
[/code]
drop table table_duplicate;
rename test to table_duplicate;
最简单,看有没有索引什么的,重新建上索引。
--如果只是查询重复的记录
select age ,tota from table
group by age tota
having count(1)>1
--如果想要删除重复数据
delete table a
where a.rowid in
( select rowid from table b where a.rowid<>b.rowid and a.age= b.age and a.tota = b.tota
)
--修正一下删除逻辑
DELETE TABLE a
WHERE ROWID NOT IN
(SELECT max(ROWID) FROM TABLE b GROUP BY age,tota)
--怎么会不支持呢?
select id from test
--------------------
1
2
3
4
5
6select id from test where id%2=1
-------------------------
1
3
5
--一个为distinct后的去重结果集,一个为所有结果集,应该可以把重复记录留下来
select * from tab
minus
select distinct * from tab--如果上面的把重复记录也去掉的话,你就把rowid也搜出来,再去重,肯定没问题了吧
select rowid, tab.* from tab
minus
select rowid, * from (select distinct tab.* from tab)--如果还还不行,那就只能笨方法了,把所有字段都group by 了