我在每个用户的排名方面都有问题是完美的,问题是当用户" a"与用户" b"
具有相同的结果我的代码
SELECT ID, Wins,
(SELECT COUNT(*)+1 FROM users WHERE Wins>x.Wins) AS rank_upper,
(SELECT COUNT(*) FROM users WHERE Wins>=x.Wins) AS rank_lower
FROM `users` x WHERE x.username='$_GET[user]'
ID wins Rank
1 23 1
2 17 2
3 17 2
4 10 3
5 10 3
我喜欢这样:
ID wins Rank
1 23 1
2 17 2
3 17 3
4 10 4
5 10 5
答案 0 :(得分:0)
比较id也可能对您有用
SELECT ID, Wins,
(SELECT COUNT(*)+1 FROM users WHERE Wins>x.Wins or (Wins=x.Wins and id<x.id)) AS Rank
FROM `users` x WHERE x.username='$_GET[user]'