>백엔드 개발 >PHP 튜토리얼 >有一个积分表,积分从高往下排,如何取出其中的一个用户的排名,积分

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

WBOY
WBOY원래의
2016-06-23 13:36:581488검색

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


我如何在这条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'


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

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'


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



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'


这么写 ,加上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

这是表结构

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'


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



我看错了。。是我的自己的问题。。 sorry。。   3Q  谢谢了。
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.