The difference between rank () over, Dense_rank (), Row_number () in Oracle

Source: Internet
Author: User

Excerpt from: http://www.linuxidc.com/Linux/2015-04/116349.htm

The difference between rank () over, Dense_rank (), Row_number () in Oracle

Suppose there is a student table student, the student table has a name, a score, a course number, and now I need to sort the students ' grades according to the course.

SELECT * FROM Student

1. Rank over () can be achieved on the student rankings, characterized by the same results as two are tied, as follows 1 2 2 4 5

Select name,       course,       throughorderbydesc as  Rank  from student;

2. Dense_rank () and rank over () are similar, but the students ' grades will not be vacated by the rank of the tie, as follows 1 2 2 3 4

Select name,       course,       throughorderbydesc as  Rank  from student;

3. Row_number This function does not need to consider whether or not to tie, that is afraid to query the same value according to the same number will be continuously ranked

Select name,       course,       throughorderbydesc as  Rank  from student;

Answering:

1. Partition by is used to partition the result set.

2. What is the difference between partition by and group by?

Partition by simply rank the original data (the number of records is the same)


Group BY is an aggregated statistic of the raw data (the number of records may be less, one for each group)

3. When you use rank over (), the null value is the largest, and if the sort field is null, it may cause null fields to be ranked first, affecting the sorting result.

Can do this:

 Over  by Order  by desc nulls last)

See Oracle Feature page for more information on Oracle http://www.linuxidc.com/topicnews.aspx?tid=12

This article permanently updates the link address : http://www.linuxidc.com/Linux/2015-04/116349.htm

The difference between rank () over, Dense_rank (), Row_number () in Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.