---
title: "oracel分组排序最大记录"
author: "lan13217"
date: "2014-08-28T17:21:05Z"
tags: []
categories: ["非技术"]
slug: "oracel"
draft: false
lastmod: "2014-08-28T17:21:28Z"
id: 2110508
url: "https://snowelf.iteye.com/blog/2110508"
---

sql分组查询最大记录
1.

```sql

select distinct first_value(emp_id) over(partition by emp_code order by tm.last_modify_tm desc) 
from employee tm 


```

2.

```sql

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)

```