oracle查询最大值的一条数据

一、方法一:(效率最高)

select * from test a 
where a.num = (select max(b.num) from tes b where a.id = b.id );

二、方法二:(效率次之)

select a.*  from test a,
(select id,max(a.num) typeindex from test group by id) b
where a.id = b.id and a.num = b.num order by a.id

三、方法三:

select a.* from test a 
inner join (select id , max(num) num from test group by id) b 
on a.id = b.id and a.num = b.num order by a.id

四、方法四:(效率最低)

select * from
(
select *,ROW_NUMBER() OVER(PARTITION BY id ORDER BY num DESC) as num from test
) t
where t.num = 1
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容