码迷,mamicode.com
首页 > 数据库 > 详细

oracle排序问题

时间:2017-07-03 16:31:21      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:字段   asc   技术分享   rom   style   images   .com   blog   test   

表格test数据

技术分享

select * from test order by name desc

结果:

技术分享

 

1-1:select * from ( select A.*,rownum rn from test A order by name asc ) where rn between 0 and 10

结果:

技术分享

1-2:select * from ( select A.*,rownum rn from test A order by name desc ) where rn between 0 and 10

结果:

技术分享

2-1:select A.*,rownum from test A where rownum between 0 and 10 order by name desc

结果:

 技术分享

2-2:select A.*,rownum from test A where rownum between 0 and 10 order by name asc

结果:

技术分享

3-1:select * from ( select A.*,Row_Number() OVER (order by name desc) as rn from test A ) where rn between 0 and 10

结果:

技术分享

3-2:select * from ( select A.*,Row_Number() OVER (order by name asc) as rn from test A ) where rn between 0 and 10

结果:

技术分享

 

 结论:第三种查询语句是先排序后取数据,而前面两种是先取数据后查询,对于不是主键的字段。

oracle排序问题

标签:字段   asc   技术分享   rom   style   images   .com   blog   test   

原文地址:http://www.cnblogs.com/lurenjia1994/p/7111109.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!