The difference between the database analysis function row_number () rank () Dense_rank ()

Source: Internet
Author: User

Direct

SELECT * FROM tab

Select B,row_number () over (order by B) from tab

When the same data is encountered, the rankings are incremented in the order in which they are recorded in the record set. The same data is encountered without affecting the sort sequence number

Select B,rank () over (order by B) from tab

When the same data is encountered, all the same data is ranked the same at the same time, and the rank between the last same record and the next record rank is vacated.

The same sort order is affected by the same data, and the next data refers to the ranking of the entire table.

Select B,dense_rank () over (order by B) from tab

When the same data is encountered, all the same data is ranked the same at this time.

The same value is ordered, the next data is ranked

The difference between the database analysis function row_number () rank () Dense_rank ()

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.