日期:2014-05-17  浏览次数:20945 次

oracle 求某一列最大值,其他列的值
比如我有一个table a

ID   Num
1    10
2    52
7    6
4    79

我现在想求出Num值最大的那一行的ID


上例中Num最大79,对应ID是4

oracle有没有简便的写法
------解决方案--------------------
select ID from a where NUM =(select max(NUM) from a);

------解决方案--------------------
with a as(

select 1 id,10 num from dual union all
select 2,52 from dual union all
select 7,6 from dual union all
select 4,79 from dual)
select ID from (
select a.*,rank() over(order by num desc) rk from a)
where rk = 1




------解决方案--------------------
select b.id from a b where not exists(select 1 from a where num>b.num)
------解决方案--------------------
select id from a where point = (select MAX(num) from a)