orcale数据库中STUDNETINFO表,删除表中重复数据并保留最新的一条的sql语句怎么写,越简单越好

解决方案 »

  1.   


    create table xu1(id number,name varchar2(30));
    insert into xu1 values(1,'a');
    insert into xu1 values(1,'a');
    insert into xu1 values(2,'b');select * from xu1 ;
      
    delete from xu1 a
    where exists (select 1
             from xu1 b
            where b.id = a.id
              and b.name = a.name
              and b.rowid <a.rowid)
      

  2.   


    delete   from    a
    where   (a.id,a.name)   in     (select   id,name from   a group   by   id,namehaving   count(*)   >   1)
    and   time not   in   (select   min(time)   from   a group   by   id,name having   count(*)> 1)
      

  3.   

    delete from stu s1 where  s1.stuid in (
    select s2.stuid from stu s2 group by s2.stuid having count(1)>1
     ) and rowid not in (SELECT max(ROWID) FROM stu s3 GROUP BY s3.stuid HAVING COUNT(*) > 1)
    我默认主键id相同时即为相同数据
      

  4.   

    楼主可以百度一下OVER,PARTITION,这样写出来的去重很好理解并且语句比较简单
      

  5.   

    delete from table where id not in (select sid from (select sid,row_number() over(partition by sid order by to_number(time) DESC) rn  from table) where rn=1)