如何根据分数给予我的球员独特的排名然后杀死? (MySQL的)
我不想要,但目前有:
Rank | Name | Score | Kills
1 | Bob | 900 | 45
2 | Moby | 400 | 35
2 | Snake | 400 | 38
3 | Dick | 240 | 20
我想要什么,但没有:
Rank | Name | Score | Kills
1 | Bob | 900 | 45
2 | Snake | 400 | 38
3 | Moby | 400 | 35
4 | Dick | 240 | 20
此外,当球员得分相同时杀戮,我仍然不希望他们拥有相同的等级,而且我有...你能帮忙,这就是我的用法:
SELECT
FIND_IN_SET(score,(SELECT GROUP_CONCAT(score ORDER BY score DESC) FROM rankme)) rank,
T1.name,
T1.score,
T1.kills,
T1.deaths,
T2.credits,
T1.connected
FROM
rankme T1
LEFT JOIN
store_players T2
ON
T1.name = T2.name
ORDER BY
T1.score DESC
编辑:我已经尝试过ORDER BY T1.score,T1.kills,它确实通过移动最多杀死的玩家来工作,但它仍然给予两个玩家相同的Rank。你是怎么解决的?
答案 0 :(得分:1)
一个选项使用相关子查询:
SELECT *
FROM
(
SELECT
1 + (SELECT COUNT(*) FROM rankme t2
WHERE t2.score > t1.score OR
(t2.score = t1.score AND t2.kills > t1.kills)) Rank,
name,
score,
kills
FROM rankme t1
) t
ORDER BY Rank;
请注意,此查询仍然有一个缺点:如果两个人在分数和杀戮方面完全并列,那么我们仍然会获得重复的排名。如果您对此感到担心,请告诉我们您希望如何打破平局。