3,491
社区成员
发帖
与我相关
我的任务
分享
select t1.*
from t1,(select c1,max(c5) c5
from t1
group by c1) t2
where t1.c1 = t2.c1 and t1.c5 = t2.c5
order by t1.c1
with t1 as
(
select 1 c1,'a' c2,'aa' c3,20 c4,'2013-05-01' c5,2222 c6 from dual union all
select 1 c1,'a' c2,'aa' c3,30 c4,'2013-05-02' c5,1111 c6 from dual union all
select 2 c1,'b' c2,'bb' c3,85 c4,'2013-05-03' c5,3333 c6 from dual union all
select 2 c1,'b' c2,'bb' c3,11 c4,'2013-05-04' c5,4444 c6 from dual
)
select c1,c2,c3,c4,c5,c6
from
(
select c1,c2,c3,c4,c5,c6,row_number() over(partition by c1 order by c5 desc) rn
from t1
)
where rn = 1
c1 c2 c3 c4 c5 c6
----------------------------------------------------------------
1 1 a aa 30 2013-05-02 1111
2 2 b bb 11 2013-05-04 4444