原来表A有号码80条,然后又导入了30条,然后共有110条,但是其中重复的数据有20条,要把这后面导入的30条中的20条删除掉,要怎么写SQL?ORacle数据库,急,谢谢

解决方案 »

  1.   


    delete from 表名 where ins_time not in(select ins_time  from(select card_num,min(ins_time) ins_time from 表名 group by card_num));SQL> select * from test;T1                   T2                           T3
    -------------------- -------------------- ----------
    A                    A                             1
    A                    A                             2
    B                    A                             3
    C                    B                             4
    D                    B                             5SQL> select t2,min(t3) from test group by t2;T2                      MIN(T3)
    -------------------- ----------
    A                             1
    B                             4
    SQL> delete from test where t3 not in(select t3 from(select t2,min(t3) t3 from test group by t2));已删除3行。SQL> commit;提交完成。SQL> select * from test;T1                   T2                           T3
    -------------------- -------------------- ----------
    A                    A                             1
    C                    B                             4
    看下是否你要的结果。
    我这里id/ins_time都不重复。
    执行前先备份下表。
      

  2.   


    delete * from tab a where rowid>(select min(rowid) from tab b where a.card_num=b.card_num)
      

  3.   

    应该可以按照rowid的大小判断,和楼上类似
      

  4.   


    DELETE FROM tablename 
    WHERE rowid IN
    (SELECT t1.rowid FROM tablename t1,tablename t2
    WHERE t1.rowid>t2.rowid AND t1.card_num=t2.card_num)
      

  5.   

    呵呵,都用rowid啊,rowid也可能重复噢,有次看某篇文章看到的。好像要用多少多少年就可能重复了,哈哈