oracle分组取每组第一条数据

scott@NIUGE> select * from t;

DOCUMENTNO UPDATE_TIME BU NAME
---------- ----------- ---------- --------------------

      1001 20061213 xx alex
      1001 20060910 yy xx
      1002 20070910 zz xx
      1002 20081213 jj dd

scott@NIUGE>
scott@NIUGE> select * from (select rank() over(partition by documentno order by update_time desc) r,a.* from t a) where r=1;

         R DOCUMENTNO UPDATE_TIME BU NAME
---------- ---------- ----------- ---------- --------------------

         1 1001 20061213 xx alex
         1 1002 20081213 jj dd

你可能感兴趣的:(oracle,常用,oracle)