There is a score table, points from high down, how to take out one of the user's ranking, points

Source: Internet
Author: User
The SQL statement is
Select A.username, (@rowNum: = @rowNum + 1) as c,a.integral as integral from Xs_user A, (Select (@rowNum: =0)) b Order by Integral DE Sc,time


How do I query the user's user name and integral based on this SQL statement?

Or how to get it in PHP?


Reply to discussion (solution)

Know the user name, direct select User name, points from table where username = user name No, it's done.

?? Out of the table??。

SELECT * FORM   (    select A.username, (@rowNum: = @rowNum + 1) as c,a.integral as integral from    xs_user A, (select (@rowNum : =0)) b Order by Integral Desc,time  ) T WHERE username= ' XXX '


This definition of user variables is still very clever.

SELECT * FORM   (    select A.username, (@rowNum: = @rowNum + 1) as c,a.integral as integral from    xs_user A, (select (@rowNum : =0)) b Order by Integral Desc,time  ) T WHERE username= ' XXX '


This definition of user variables is still very clever.



SELECT * FROM  (    select A.username, (@rowNum: = @rowNum + 1) as c,a.integral as integral from    xs_user A, (select (@rowNum : =0)) b Order by Integral Desc,time  ) T WHERE username=18511337033 '


In this case, plus the Where condition will be an error, no where condition is normal.

Here is the error message.
[SQL] SELECT * FROM  (    select A.username, (@rowNum: = @rowNum + 1) as c,a.integral as integral from    xs_user A, (select (@rowNum : =0)) b Order by Integral Desc,time  ) T WHERE username=18511337033 ' [ERR] 1064-you has an error in your SQL syntax ; Check the manual-corresponds to your MySQL server version for the right syntax-to-use "at line 6

This is the table structure

SELECT * FORM   (    select A.username, (@rowNum: = @rowNum + 1) as c,a.integral as integral from    xs_user A, (select (@rowNum : =0)) b Order by Integral Desc,time  ) T WHERE username= ' XXX '


This definition of user variables is still very clever.



I read it wrong. It's my own problem. Sorry. 3Q Thank you.
  • 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.