我正在尝试将以下代码实现到我自己的代码中。
以下是我尝试实施的代码。获得有关系的排名并且在关系之后排名是不连续的。
SET @rnk=0;
SET @rank=0;
SET @curscore=0;
SELECT score,ID,rank FROM (
SELECT AA.*,BB.ID,
(@rnk:=@rnk+1) rnk,
(@rank:=IF(@curscore=score,@rank,@rnk)) rank,
(@curscore:=score) newscore
FROM (
SELECT * FROM (
SELECT COUNT(1) scorecount,score
FROM scores GROUP BY score
) AAA
ORDER BY score DESC
) AA LEFT JOIN scores BB USING (score)
) A;
以下是我从中获取代码的链接。这是第二个答案。
https://dba.stackexchange.com/questions/13703/get-the-rank-of-a-user-in-a-score-table
我的代码如下。我换了#34;得分"使用" totalPoints"。这就是我的意思。
我遇到了代码的两部分问题。
这一行,BB.ID部分。
SELECT AA.*, BB.ID,
这一行。
) AA LEFT JOIN scores BB USING (score)
我知道代码在做什么我只是不知道如何用我的代码和表替换这些部分以使它们工作。
SET @rnk=0;
SET @rank=0;
SET @curscore=0;
SELECT AA.*, BB.ID,
(@rnk:=@rnk+1) rnk,
(@rank:=IF(@curscore=totalPoints,@rank,@rnk)) rank,
(@curscore:=totalPoints) newPoints
FROM (
SELECT * FROM (
SELECT COUNT(1) scorecount, totalPoints FROM (
#----------start of my code
SELECT *, (totalWins+(totalPushs*.5)) AS totalPoints, totalWins+totalLost+totalPushs AS totalBets FROM (
SELECT *, SUM(win) AS totalWins, SUM(lost) AS totalLost, SUM(push) AS totalPushs FROM (
SELECT *, (finalResult = 'Winner') AS win, (finalResult = 'Loser') AS lost, (finalResult = 'Push') AS push FROM (
SELECT nflp_users.userID, userName, avatar, teamColor,
IF (pickID=visitorID, visitorResult, homeResult) AS finalResult
FROM nflp_users
JOIN nflp_picks
ON nflp_users.userID = nflp_picks.userID
JOIN nflp_schedule
ON nflp_picks.gameID = nflp_schedule.gameID
) x
) x
GROUP BY userID
) x
#----------end of my code
) x GROUP BY totalPoints
) AAA
ORDER BY totalPoints DESC
) AA LEFT JOIN scores BB USING (score)