您的位置:首页 > 数据库 > Oracle

oracle多列最大值的sql

2011-11-25 09:53 357 查看
select id,r,sr,kbn from (

select distinct id

,row_number() over(partition by id order by r desc)
rn

,row_number() over(partition by id,r order by sr desc)
rn2

,row_number() over(partition by id,r,sr order by kbn desc)
rn3

,r

,sr

,kbn

from test_soukou

)

where rn = 1 and rn2=1 and rn3=1

--order by id,v1,v2,v3

select a.id, a.r, a.sr, max(kbn) as kbn

from

(

select t.id, t.r, max(sr) as sr

from (select id, max(r) as r from test_soukou group by id) t1, test_soukou t

where t1.id = t.id and t1.r = t.r group by t.id, t.r

) a, test_soukou b

where a.id = b.id and a.r=b.r and a.sr=b.sr group by a.id,a.r,a.sr
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: