Row_number () function

Source: Internet
Author: User

-- Excerpted from "T-SQL programming entry classic"

The row_number () function returns an increasing integer based on the value of the order by clause passed to the function as a parameter. If the order by value of row_number matches the order in the result set, the return value is incremented and arranged in ascending order. If the value of the order by clause of row_number is different from the order in the result set, these values are not listed in order, but they represent the order of the order by clause of the row_number function. The example and result are as follows:

SelectProductcategoryid, name, row_number ()Over(Order ByName)AsRownumFromPorduction. productcategoryOrder ByName

The order by clause in the row_number () call matches the query results sequentially, so these results are listed in order.

However, when another order by clause is used in a function call, these values are unordered.

SelectProductcategoryid, name, row_number ()Over(Order ByName)AsRownumFromPorduction. productcategoryOrder ByProductcategoryid

 

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.