本帖最后由 dctg2003 于 2011-10-25 12:48:02 编辑

解决方案 »

  1.   

    delete DQ from DQ as a where exists(select 1 from DQ where A=a.A and B>a.B)--保留最大的一條
      

  2.   


    create table dq (A number,B date);
    insert into dq values(001,to_date('2001-1-1','yyyy-mm-dd'));
    insert into dq values(001,to_date('2005-1-1','yyyy-mm-dd'));
    insert into dq values(002,to_date('2005-1-1','yyyy-mm-dd'));
    insert into dq values(004,to_date('2003-1-1','yyyy-mm-dd'));
    insert into dq values(004,to_date('2009-1-1','yyyy-mm-dd'));
    delete from DQ a where exists(select 1 from DQ where A=a.A and B<a.B);
    drop table dq;
      

  3.   

    刚发的有些错drop table dq;
    create table dq (A number,B date);
    insert into dq values(001,to_date('2001-1-1','yyyy-mm-dd'));
    insert into dq values(001,to_date('2005-1-1','yyyy-mm-dd'));
    insert into dq values(002,to_date('2005-1-1','yyyy-mm-dd'));
    insert into dq values(004,to_date('2003-1-1','yyyy-mm-dd'));
    insert into dq values(004,to_date('2009-1-1','yyyy-mm-dd'));
    delete from DQ a where exists (select A from DQ where A=a.A and B<a.B group by A having count(A)>0);
      

  4.   

    上面还是错,这次真没错了drop table dq;
    create table dq (A number,B date);
    insert into dq values(001,to_date('2001-1-1','yyyy-mm-dd'));
    insert into dq values(001,to_date('2005-1-1','yyyy-mm-dd'));
    insert into dq values(002,to_date('2005-1-1','yyyy-mm-dd'));
    insert into dq values(004,to_date('2003-1-1','yyyy-mm-dd'));
    insert into dq values(004,to_date('2009-1-1','yyyy-mm-dd'));
    delete from DQ a where not exists (select 1 from DQ where A=a.A and B>a.B) and (select count(1) from DQ where A=a.A) <>1;