oracle sql 分组求最大值后,要显示其它列

select

t_a.a,t_a.b,max(t_a.c) c,

 

MAX (t_a.d)KEEP (DENSE_RANK FIRST
      ORDER BY t_a.c _ DESC)  d_

from t_a

group by

t_a.a,t_a.b

 

 

 

---------------------------------------------------------------------------------------------------------------------

单表

      select max(t2.main_id) KEEP(DENSE_RANK FIRST    ORDER BY t2.creatime  DESC)

        from 

        T_FILE_001_DOCUMENT_GENERATE t1,T_common_001_MAIN t2 

        where t1.APPLY_CODE=t2.main_id and t1.approval_num='吉长辖演许字【2013】第001号'

 

 

 

------------------------------------

-- Created on 2013-10-25 by  删 除公司名称重复的数据

declare 

  -- Local variables here

l_rowid  rowid;

begin

  -- Test statements here

  for cur_v  in(

  

       select comp_name from T_Service_017_Mainbasicinfo  group by comp_name having count(*)>1

  ) loop

    

      

       select MAX (rowid) KEEP (DENSE_RANK FIRST

      ORDER BY T.Sys_Receive_Date  DESC)  into l_rowid from T_Service_017_Mainbasicinfo t where t.comp_name =cur_v.comp_name  ;

        

      delete from T_Service_017_Mainbasicinfo t where comp_name =cur_v.comp_name  and rowid<> l_rowid ;

  end loop;

end;

 

猜你喜欢

转载自thinktothings.iteye.com/blog/1559173
今日推荐