日期:2014-05-17  浏览次数:20902 次

求最高效的去重SQL语句
在ORACLE中...
要把二字段一起相同的数据给找出来,只留一条,剩下的不要。

有表A,有字段id,mobile,note_content等字段,现在要把mobile和note_content二字段一起相同的去掉(是字段一起相同的)
相同的数据可能有多条....
数据量大概在五百万左右...
用in语句速度不行...
重复率不定....

试了好多种方法都效率不高。。。希望有SQL高手帮忙。。。谢谢!!

------解决方案--------------------
delete
from A a
where a.rowid < 
(select max(rowid)
 from A b
 where a.mobile= b.mobile
and a.note_content = b.note_content)
不知道这样效率如何


------解决方案--------------------
select t.* from (select t.id,
t.mobile,
t.note_content,
row_number() OVER(PARTITION BY t.mobile,t.note_content ORDER BY t.row_id desc) rn
from a t where t.mobile = t.note_content) t
where t.rn =1
看看呢.
------解决方案--------------------
探讨
在ORACLE中...
要把二字段一起相同的数据给找出来,只留一条,剩下的不要。

有表A,有字段id,mobile,note_content等字段,现在要把mobile和note_content二字段一起相同的去掉(是字段一起相同的)
相同的数据可能有多条....
数据量大概在五百万左右...
用in语句速度不行...
重复率不定....

试了好多种方法都效率不高。。。希望有……

------解决方案--------------------
delete from A t where t.rowid!=(select min(id) from A where mobile = t.mobile and note_content = t.note_content);

------解决方案--------------------
delete from A t where t.rowid!=(select min(rowid) from A where mobile = t.mobile and note_content = t.note_content);

------解决方案--------------------
索引情况?
------解决方案--------------------
探讨
在ORACLE中...
要把二字段一起相同的数据给找出来,只留一条,剩下的不要。

有表A,有字段id,mobile,note_content等字段,现在要把mobile和note_content二字段一起相同的去掉(是字段一起相同的)
相同的数据可能有多条....
数据量大概在五百万左右...
用in语句速度不行...
重复率不定....

试了好多种方法都效率不高。。。希望有……