表A中有字段A1(字符型),A2(字符型)和A3(整型),字段A1中有很多重复记录。
现写一个程序,每一个重复的记录都保留A3值最大的一条记录。其它的都删除掉。可以用Delphi也可以pl-sql来写。  那一位有比较简单的方法呢?

解决方案 »

  1.   

    select A1,max(A3) from A group by A1
      

  2.   

    delete  from A where  (a1+a2+Str(a3)) not  in (select (a1+a2+Str(max(a3)))al  from A group by a1)
      

  3.   

    delete B from A  B where exists (select * from A where A1=B.A1 and A3>B.A3)
      

  4.   

    赞同 shengliqiang168(ValorSlq) 写法
      

  5.   

    delete table where exists (select * from table  where a1=table.a1 and a3>table.a3)
      

  6.   

    DELETE FROM 表A AS TEMP WHERE A3<(SELECT MAX(A3) FROM 表A WHERE A1=TEMP.A1)
      

  7.   

    create table #a (a1 varchar(20),a2 varchar(20),a3 integer)insert into #a values ('aaa','bbb','1')
    insert into #a values ('aaa','bcb','2')
    insert into #a values ('aaa','bcd','3')
    insert into #a values ('bbb','bbb','1')
    insert into #a values ('bbb','bba','2')
    insert into #a values ('bbb','bbc','3')select * from #a as temp where a3<(select max(a3) from #a as b where b.a1=temp.a1)aaa bbb 1
    aaa bcb 2
    bbb bbb 1
    bbb bba 2