oracel分组排序最大记录

sql分组查询最大记录
1.
select distinct first_value(emp_id) over(partition by emp_code order by tm.last_modify_tm desc) 
from employee tm 


2.
select *
  from (select max(t.created_tm) as maxid,emp_code
          from EMPLOYEE t
         where t.valid_flg = 1
         group by t.emp_code) mte
  left join EMPLOYEE te
    on (mte.maxid=te.created_tm and mte.emp_code=te.emp_code)

猜你喜欢

转载自snowelf.iteye.com/blog/2110508