select A,B,MAX(Create_Date) 
  from tbl 
  where A=B
  GROUP BY A,B

解决方案 »

  1.   

    SELECT * FROM TBNAME 
    WHERE (A,B,CREATE_DATE) IN (
    SELECT A,B,MAX(CREATE_DATE) FROM TBNAME GROUP BY A,B);
      

  2.   

    select * from
    (select row_number() over(partition by a,b order by Create_Date desc) rm,a.* from tabname a)
    where rm=1
      

  3.   

    select * 
    from TBName
    where exists (
       select *
       from TBName
       where a = b
       group by a,b );
      

  4.   

    SQL> desc test3;
    Name Type         Nullable Default Comments 
    ---- ------------ -------- ------- -------- 
    A    VARCHAR2(10) Y                         
    B    VARCHAR2(10) Y                         
    C    VARCHAR2(10) Y       SQL> select * from test3;A          B          C
    ---------- ---------- ----------
    1          1          01/01/2003
    1          1          01/02/2003
    2          2          01/01/2003
    2          2          01/02/2003SQL> 
    SQL> select a,b,c from (select
      2     a,b,c,rank() over(partition by a,b order by c desc) rn
      3  from test3
      4   )
      5  where rn = 1
      6  ;A          B          C
    ---------- ---------- ----------
    1          1          01/02/2003
    2          2          01/02/2003
      

  5.   

    谢谢各位帮忙!
    to lianhg(lianhg)
    我试过你这种方法,如果还要列出其它字段,好象是不行的。
      

  6.   


     试试我的嘛:)
      select A,B,MAX(Create_Date) 
      from tbl 
      GROUP BY A||B
      

  7.   

    SQL> select * from testme;        ID          A          B CREATEDATE
    ---------- ---------- ---------- ----------
             1          1          1 01-1月 -03
             2          1          1 01-2月 -03
             3          2          2 01-1月 -03
             4          2          2 01-2月 -03
             5          1          2 01-2月 -03SQL> select bt.id,bt.a,bt.b,bt.createdate from(select a,b,max(createdate) maxd f
    rom testme group by a,b having a=b) at,testme bt where at.a=bt.a and at.b=bt.b a
    nd at.maxd=bt.createdate;        ID          A          B CREATEDATE
    ---------- ---------- ---------- ----------
             2          1          1 01-2月 -03
             4          2          2 01-2月 -03