删除重复数据

首先来创建一个表Test

 

create table test7
(
       id number,
       name varchar2(20)
) 

 

录入一些数据

 

insert into test values(1,'A')
insert into test values(1,'A')
insert into test values(1,'A')
insert into test values(1,'B')
insert into test values(1,'B')
insert into test values(1,'C')
insert into test values(2,'D')
insert into test values(2,'D') 

SQL> select * from test; 

        ID NAME
---------- --------------------
         1 A
         1 A
         1 A
         1 B
         1 B
         1 C
         2 D
         2 D 

已选择8行。 

 

delete from test a where rowid > (select min(rowid) from test b where b.id=a.id and b.name=a.name);

 

SQL> delete from test a where rowid > (select min(rowid) from test b where b.id=a.id and b.name=a.name); 

已删除4行。 

已用时间:  00: 00: 00.01 

执行计划
----------------------------------------------------------
   0      DELETE STATEMENT Optimizer=ALL_ROWS (Cost=8 Card=1 Bytes=64)
   1    0   DELETE OF 'TEST'
   2    1     HASH JOIN (Cost=8 Card=1 Bytes=64)
   3    2       VIEW OF 'VW_SQ_1' (VIEW) (Cost=4 Card=4 Bytes=128)
   4    3         SORT (GROUP BY) (Cost=4 Card=4 Bytes=128)
   5    4           TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=3 Card
          =4 Bytes=128) 

   6    2       TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=3 Card=4 B
          ytes=128) 

统计信息
----------------------------------------------------------
          0  recursive calls
          6  db block gets
         14  consistent gets
          0  physical reads
          0  redo size
        627  bytes sent via SQL*Net to client
        610  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
          4  rows processed 

 

 

你可能感兴趣的:(sql,C++,c,.net,Access)