SQL adds the number (ROW_NUMBER) to the query result and merges multiple query results.

Source: Internet
Author: User
Tags add numbers

The original author seems to be called topcat. I understood it myself and wrote it back with my memory.
If Select Name From StudentTable is used, the result is:
Name
Zhang San
Li Si
If Select ROW_NUMBER () as rowindex, Name From StudentTable is used, the displayed result is
ROWINDEX Name
1 Zhang San
2 Li Si
Of course, you do not need to add numbers to the query results, because the List itself has numbers when displaying data. But the advantage of this is that you can query multiple result sets in the database, and then return them to the customer after the ROWINDEX field is linked together, which is more flexible.
There are also several optional parameters:
1. ROW_NUMBER ()
Example: Select ROW_NUMBER () OVER (order by Name) as rowindex, Name From StudentTable
The result is sorted in sequence.
2. RANK ()
Example: Select RANK () OVER (order by Name) as rowindex, Name From StudentTable
The result is that if five people are called Michael Jacob, then all five are called Michael Jacob, and then the first Mr. Li is called Michael Jacob, and so on.
3. DENSE_RANK ()
Similar to the previous one, the difference is that the first Li Si is No. 2.

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.