SQL server2008 sort function

Source: Internet
Author: User

Sort functions:

1.row_number () over (ordered by Liename): A unique line number is given for each row, sorted by the field following order by

Select Row_number () over (order by iname Desc) as ROWID, iname from test

2.Rank (): The field values are the same with the same ordinal number, and the ordinal number may be discontinuous, according to the field following the order by

Select DISTINCT rank (iname desc) as ROWID, iname,iage from test

3. Dense_rank (): According to the order by the field after ordering by, the field value after the orders by the same ordinal number is the same, serial number is continuous

SELECT DISTINCT Dense_rank () over (order by iname Desc) as ROWID, iname from test

4. Ntile (): First, according to the order by the field after the sort, and then the sorting results into a set of several groups, and for each group to specify a group number

SELECT DISTINCT Ntile (5) over (order by iname Desc) as rowID iname,iage

Summarize:

1.row_number () over (ordered by Liename): A unique line number is given for each row, sorted by the field following order by

2.Rank (): The field values are the same with the same ordinal number, and the ordinal number may be discontinuous, according to the field following the order by

3. Dense_rank (): According to the order by the field after ordering by, the field value after the orders by the same ordinal number is the same, serial number is continuous

4. Ntile (): First, according to the order by the field after the sort, and then the sorting results into a set of several groups, and for each group to specify a group number

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.