There is an integral table, where the points are arranged down from the top, how to retrieve the ranking and points of one of the users

Source: Internet
Author: User
There is an integral table, where the points are arranged down from the top to the bottom, and how to retrieve the ranking of one of the users, the integral SQL statement is
Select. username, (@ rowNum: = @ rowNum + 1) as c,. integral as points from xs_user a, (Select (@ rowNum: = 0) B order by integral DESC, time


On the basis of this SQL statement, how can I query the user name and points.

Or how can I get it in php?


Reply to discussion (solution)

Do you know the user name? directly select the user name, Points from table where user name = user name. isn't that all done?

?? Output Table ??.

SELECT * FORM (select. username, (@ rowNum: = @ rowNum + 1) as c,. integral as points from xs_user a, (Select (@ rowNum: = 0) B order by integral DESC, time) T WHERE username = 'XXX'


This method of defining user variables is clever.

SELECT * FORM (select. username, (@ rowNum: = @ rowNum + 1) as c,. integral as points from xs_user a, (Select (@ rowNum: = 0) B order by integral DESC, time) T WHERE username = 'XXX'


This method of defining user variables is clever.



SELECT * From (select. username, (@ rowNum: = @ rowNum + 1) as c,. integral as points from xs_user a, (Select (@ rowNum: = 0) B order by integral DESC, time) T WHERE username = 18511337033'


In this case, an error will be reported when the where condition is added, and it will be normal if no where condition is available.

Below is the error message.
[SQL] SELECT * From (select. username, (@ rowNum: = @ rowNum + 1) as c,. integral as points from xs_user a, (Select (@ rowNum: = 0) B order by integral DESC, time) t where username = 18511337033 '[Err] 1064-You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 6

This is the table structure

SELECT * FORM (select. username, (@ rowNum: = @ rowNum + 1) as c,. integral as points from xs_user a, (Select (@ rowNum: = 0) B order by integral DESC, time) T WHERE username = 'XXX'


This method of defining user variables is clever.



I saw it wrong .. It's my own problem .. .. 3Q thanks.

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.