Oracle中rank() over, dense_rank(), row_number() 的区别
Oracle中rank() over,dense_rank(),row_number() 的区别 假设现在有一张学生表student,学生表中有姓名、分数、课程编号,现在我需要按照课程对学生的成绩进行排序。 select * from student
1. rank over ()可以实现对学生排名,特点是成绩相同的两名是并列,如下1 2 2 4 5 select name,
2. dense_rank()和rank over()很像,但学生成绩并列后并不会空出并列所占的名次,如下1 2 2 3 4 select name,宋体; font-size:14px; line-height:22.4px; margin-bottom:0px; margin-left:0px; margin-right:0px; margin-top:0px; text-align:justify; width:auto; word-wrap:break-word"> dense_rank() over(partition by course order by score desc) as rank
3. row_number这个函数不需要考虑是否并列,那怕根据条件查询出来的数值相同也会进行连续排名 select name,宋体; font-size:14px; line-height:22.4px; margin-bottom:0px; margin-left:0px; margin-right:0px; margin-top:0px; text-align:justify; width:auto; word-wrap:break-word"> row_number() over(partition by course order by score desc) as rank
1. partition by用于给结果集进行分区。 2. partition by和group by有何区别? partition by只是将原始数据进行名次排列(记录数不变)
3. 使用rank over()的时候,空值是最大的,如果排序字段为null,可能造成null字段排在最前面,影响排序结果。 可以这样: rank over(partition by course order by score desc nulls last) 更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12 本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-04/116349.htm (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- Swift 实践篇之链式 UI 代码
- Validate Matches in Procedural Code (用程序码验证匹配)
- 在SQLite中使用索引优化查询速度
- Oracle:for update 和select t.*,t.rowid编辑数据的区别
- swift – editActionsForRowAtIndexPath不能在iOS 8上使用X
- 【沫沫金原创】Oracle克隆空库 新建一模一样的数据库不带数
- swift 改变按钮文字图标的位置 frame.offsetInPlace改变按钮
- reactjs – 在React.js中重复跨越?
- XML基础以及用DOM4j读取数据
- macos – 屏幕中的中心窗口