我需要给TC5分配一个等级而不是id。

SELECT a.id, a.user_id, a.tc1, a.tc4, min(a.tc5), a.tc2, b.avatar, c.username, @curRank := @curRank + 1 AS Rank
FROM
treningove_casy a INNER JOIN
sn_users b ON a.user_id=b.id INNER JOIN
users c ON a.user_id=c.id , (SELECT @curRank := 0) r
WHERE  a.tc2 LIKE  'Motokáry Modrice'
GROUP BY a.user_id

所以情况如何。请帮忙
mysql - MySQL中的等级函数分配等级-LMLPHP
修改后的代码
SELECT x.*, (@curRank := @curRank + 1) as Rank
FROM (SELECT a.id, a.user_id, a.tc1, a.tc4, min(a.tc5) as tc5,
             a.tc2, b.avatar, c.username,
      FROM sbhgl_chronoengine_chronoforms_datatable_treningove_casy a INNER JOIN
           sbhgl_jsn_users b
           ON a.user_id = b.id INNER JOIN
           sbhgl_users c
           ON a.user_id = c.id
      WHERE  a.tc2 LIKE  'Motokáry Modřice'
      GROUP BY a.user_id
     ) x CROSS JOIN
     (SELECT @curRank := 0) params
ORDER BY tc5 DESC;

最佳答案

SELECT a.id, a.user_id, a.tc1, a.tc4, a.tc2, b.avatar, c.username,
    (select rank from (SELECT
        IF (@score=s.tc5, @rank:=@rank, @rank:=@rank+1) rank,
        @score:=s.tc5 tc5s
        FROM treningove_casy s,
        (SELECT @score:=0, @rank:=0) r
        ORDER BY tc5 DESC) s ) as rank
FROM
treningove_casy a INNER JOIN
sn_users b ON a.user_id=b.id INNER JOIN
users c ON a.user_id=c.id , (SELECT @curRank := 0) r
WHERE  a.tc2 LIKE  'Motokáry Modrice'
GROUP BY a.user_id

你可以试试以上的解决方案,希望对你有帮助。

关于mysql - MySQL中的等级函数分配等级,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41197737/

10-13 03:22