我正在做一个需要硬编码排名的项目(请不要规范化评论)。该示例有一个分数表。每条得分记录都与一个人和一个特定的游戏迭代有关。我们只想对一个人在游戏的特定迭代中的最高得分进行排名,因为一个人可能在某个时候打破自己的得分并拥有多个记录。以下查询用于标记每个人在特定游戏迭代中的最高得分,以便可以单独对其进行排名。
以下是非常慢的,我想加快速度:
/* Define a game iteration */
SET @VarID=(can be any number from 1-200k);
/* WITHIN A game iteration RESET ALL OF THE PERSONAL BEST */
UPDATE scores m
SET m.personal_best='0'
WHERE VarID = @VarID;
/* IDENTIFY THE "BEST" (in this case the highest score per PeopleID) */
UPDATE scores m
SET m.personal_best='1'
WHERE m.ScoreID IN
(
SELECT _scoreID
FROM
(
SELECT ScoreID as _scoreID FROM scores WHERE VarID = @VarID AND NewScore = ( select max(NewScore) from scores i where i.PeopleID = scores.PeopleID AND VarID = @VarID ) ORDER BY VarID, NewScore DESC
) s
) AND VarID = @VarID;