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

kglay123 2015-04-09 05:04:56
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
``````

...全文
231 5 打赏 收藏 转发到动态 举报

5 条回复

kglay123 2015-04-10
• 打赏
• 举报

``````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'``````

kglay123 2015-04-10
• 打赏
• 举报

``````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'
``````

``````
[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

``````

xuzuning 2015-04-09
• 打赏
• 举报

``````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'``````

• 打赏
• 举报

luozhongkai1991 2015-04-09
• 打赏
• 举报

21,890

• 近7日
• 近30日
• 至今