比如我有一个table aID Num
1 10
2 52
7 6
4 79我现在想求出Num值最大的那一行的ID
上例中Num最大79,对应ID是4oracle有没有简便的写法
1 10
2 52
7 6
4 79我现在想求出Num值最大的那一行的ID
上例中Num最大79,对应ID是4oracle有没有简便的写法
解决方案 »
- 问个算去年同期值的sql
- 咨询高手一个查询语句,急
- ALTER TABLE table_name DEALLOCATE UNUSED;
- oralce与其他数据库的异构连接——记半个月的心路历程
- 急:在as4u2上oracm找不到hangcheck-timer
- oracle8.17将安装目录全拷贝后恢复出错!
- 谁能给我个Oracle客户端下载地址啊,急急急!!!
- ORACLE有时出现超过打开的最大的游标数错误,请问怎么解决!(在线等待,一定给分)
- 我在system下建立的表和pl/sql程序,可以移植到别的用户中吗,如何移植
- 作业删除错误,请协助解决!!
- 关于两表关联的update及delete的问题
- 使用OCI C语言开发中 关于调用存储过程 返回值问题
select a.*,rank() over(partition by ID,order by num desc) rk from a)
where rk = 1
这样如果两个num一样大,他返回的ID和NUM的值对应不起来
假如我还有2列HIST GROUP ID Num
2012/01/05 A 1 10
2011/05/06 B 2 52
2012/08/09 C 7 6
2011/07/05 D 4 79
我要返回某个Group,num最大值,对应的ID
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 '2012/05/06','B',2,52 from dual union all
select '2012/08/09','C',7,6 from dual union all
select '2012/07/05','D',4,79 from dual union all
select '2012/01/05','E',5,79 from dual)
select id,num from (
select a.*,rank() over(partition by group1 order by num desc) rk from a)
where rk = 1
每个group中num最大值
from t
group by t.group) a,t
where t.group=a.gr and t.num= a.nu选择每个group下num最大的id