Oracle只取第一行

  1. 伪列rownum,不能用于排序和分组,除非套一层select

select col01,col02 from table1 where rownum = 1;
select col02, col02 from (select col01, col02 from table1 order by col02 ) where rownum = 1;
  1. row_number() over(),必须套一层select

select * from (
  select col01,col02,
  row_number() over(partition by col03 order by col05 DESC) as num2
  from table1 t1
) t2
where t2.num2=1;

参考资料:E11882_01/server.112/e41084/functions156.htm#i86310

  1. fetch first 版本12c才支持

select col01, col02
from table1 
order by col03
fetch first 1 rows only;
  1. offset fetch next 版本12c才支持

select col02, col02
from table1
order by col03
offset 1 rows fetch next 1 rows only;
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容