Home > Backend Development > PHP Tutorial > 有一个积分表,积分从高往下排,如何取出其中的一个用户的排名,积分

有一个积分表,积分从高往下排,如何取出其中的一个用户的排名,积分

WBOY
Release: 2016-06-23 13:36:58
Original
1470 people have browsed it

sql语句是

select a.username,(@rowNum:=@rowNum+1) as c,a.integral as 积分from xs_user a,(Select (@rowNum :=0 ) ) b order by integral DESC,time
Copy after login


我如何在这条sql语句的基础上,查询出用户的用户名,积分。

或者如何在php中获取一下?


回复讨论(解决方案)

知道用户名么, 直接select 用户名,积分 from table where 用户名=用户名不就完事了么

??出表??。

SELECT * FORM   (    select a.username,(@rowNum:=@rowNum+1) as c,a.integral as 积分    from xs_user a,(Select (@rowNum :=0 ) ) b order by integral DESC,time  ) T WHERE username='XXX'
Copy after login
Copy after login
Copy after login


这种定义用户变量的写法还是很巧妙的

SELECT * FORM   (    select a.username,(@rowNum:=@rowNum+1) as c,a.integral as 积分    from xs_user a,(Select (@rowNum :=0 ) ) b order by integral DESC,time  ) T WHERE username='XXX'
Copy after login
Copy after login
Copy after login


这种定义用户变量的写法还是很巧妙的



SELECT * From  (    select a.username,(@rowNum:=@rowNum+1) as c,a.integral as 积分    from xs_user a,(Select (@rowNum :=0 ) ) b order by integral DESC,time  ) T WHERE username=18511337033'
Copy after login


这么写 ,加上where条件就会报错,没有where条件 就正常。

下面这是错误信息。
[SQL] SELECT * From  (    select a.username,(@rowNum:=@rowNum+1) as c,a.integral as 积分    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
Copy after login

这是表结构

SELECT * FORM   (    select a.username,(@rowNum:=@rowNum+1) as c,a.integral as 积分    from xs_user a,(Select (@rowNum :=0 ) ) b order by integral DESC,time  ) T WHERE username='XXX'
Copy after login
Copy after login
Copy after login


这种定义用户变量的写法还是很巧妙的



我看错了。。是我的自己的问题。。 sorry。。   3Q  谢谢了。
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template