Welcome 微信登录

首页 / 数据库 / MySQL / Oracle中删除重复的记录

1 建示例表SQL> create table tt(name varchar2(10), kecheng varchar2(10), score number);Table created2  插入数据SQL> insert into tt values(1,2,3); 1 row insertedSQL> insert into tt values(1,2,3); 1 row insertedSQL> insert into tt values(1,2,4); 1 row insertedSQL> insert into tt values(1,2,4); 1 row insertedSQL> insert into tt values(1,2,4); 1 row insertedSQL> insert into tt values(1,2,4); 1 row insertedSQL> insert into tt values(1,2,4); 1 row insertedSQL> insert into tt values(1,2,4); 1 row insertedSQL> insert into tt values(1,2,5); 1 row insertedSQL> insert into tt values(1,2,5); 1 row insertedSQL> insert into tt select * from tt; 10 rows insertedSQL> insert into tt select * from tt; 20 rows insertedSQL> insert into tt select * from tt; 40 rows insertedSQL> insert into tt select * from tt; 80 rows insertedSQL> insert into tt select * from tt; 160 rows insertedSQL> insert into tt select * from tt; 320 rows insertedSQL> insert into tt select * from tt; 640 rows insertedSQL> insert into tt select * from tt; 1280 rows insertedSQL> insert into tt select * from tt; 2560 rows insertedSQL> insert into tt select * from tt; 5120 rows insertedSQL> insert into tt select * from tt; 10240 rows insertedSQL> insert into tt select * from tt; 20480 rows insertedSQL> insert into tt select * from tt; 40960 rows inserted SQL> select count(*) from tt;   COUNT(*)----------     819203 删除方法1SQL> delete from tt a  2   where a.rowid != (select max(b.rowid)  3                       from tt b  4                      where b.name = a.name  5                        and b.kecheng = a.kecheng  6                        and b.score = a.score); 81917 rows deletedExecuted in 2.25 seconds4 删除方法2SQL> delete from tt  2   where rowid in (select rid  3                     from (select rowid as rid,  4                                  row_number() over(partition by name, kecheng, score order by rowid) as rn  5                             from tt) a  6                    where a.rn > 1); 81917 rows deleted Executed in 1.875 seconds81917 rows deleted5 比较1. 方法1消耗io较少, cost比较大(14526), 但是更消耗cpu2. 方法2消耗io较多, 但是cost较小(1007), 消耗cpu也较少Oracle锁的相关脚本如何用sys as sysdba权限连接数据库进行Exp/Imp相关资讯      Oracle数据库  Oracle入门教程  oracle数据库教程 
  • Oracle数据库全球化  (03月01日)
  • Oracle数据库日期过滤方法性能比较  (02/02/2015 13:20:26)
  • Oracle数据库安装中端口被占用问题  (10/29/2014 07:42:24)
  • 在CentOS 6.6上搭建C++运行环境并  (10/10/2015 19:44:40)
  • Oracle数据库无法使用localhost和  (11/14/2014 16:39:10)
  • 使用SQLT来构建Oracle测试用例  (08/28/2014 06:17:41)
本文评论 查看全部评论 (0)
表情: 姓名: 字数