mysql-Implementing Line Numbers

Source: Internet
Author: User
Tags oracle rownum

At present, MySQL does not support like Oracle RowNum, in the internet also looked for a lot, various ways, their own summary, the implementation method is as follows

New table:

userid Salay
Zhangsan 10000
Lisi 12000
Wangwu 15000

Now you want to sort by salay and get the corresponding line number, SQL is as follows

select userid,(@rowNum:[email protected]+1)asfromuserjoin (select (@rowNum:=0orderbydesc

The output results are as follows:

RowNo userid Salay
1 Wangwu 50000
2 Lisi 12000
3 Zhangsan 10000

mysql-Implementing Line Numbers

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.