MYSQL Stats Rankings

Source: Internet
Author: User


Example:

SET @ranking =0;select *, @ranking: [email protected]+1 as ' ranking ' from table ORDER by ' members ' DESC;

1. Assign the user variable @ranking first, and the user variable in MySQL begins with @ without prior declaration;

2. Then sort by a field and add the following code to the return field:

@ranking: [Email protected]+1

This results in a query that contains the ranking field, which represents the current rank.

Problems encountered:

1. Execute statement prompt syntax error, separate execution without error.

2. Data paging

SET @ranking = Current Page * Number of pages per page;

3. Ranking of a record

SET @ranking =0;select * FROM (SELECT *, @ranking: [e-mail protected]+1 as ' ranking ' from table ORDER by ' members ' DESC) as re Sult where result.id = 17;

The above are optimized;



MYSQL Stats Rankings

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.