Maison > développement back-end > tutoriel php > 有一个积分表,积分从高往下排,如何取出其中的一个用户的排名,积分

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Libérer: 2016-06-23 13:36:58
original
1524 Les gens l'ont consulté

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
Copier après la connexion


我如何在这条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'
Copier après la connexion
Copier après la connexion
Copier après la connexion


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

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'
Copier après la connexion
Copier après la connexion
Copier après la connexion


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



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'
Copier après la connexion


这么写 ,加上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
Copier après la connexion

这是表结构

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'
Copier après la connexion
Copier après la connexion
Copier après la connexion


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



我看错了。。是我的自己的问题。。 sorry。。   3Q  谢谢了。
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal