我有来自Stack Overflow的以下SQL查询,它的工作正常。 This is the link to the original answer
如果有任何关系,我希望以下查询按以下顺序输出排名:
1,1,3,4,5,6,6,6,9,10 ....等。
这是SQL查询:
SELECT idno, name, rank,total_score
FROM (SELECT *, IF(@marks=(@marks:=total_score), @auto, @auto:=@auto+1) AS rank
FROM (SELECT * FROM
(SELECT idno, name, SUM(score) AS total_score
FROM jbit,
(SELECT @auto:=0, @marks:=0) as init
GROUP BY name) sub ORDER BY total_score DESC)t) as result
WHERE idno ='1'
答案 0 :(得分:0)
MySQL甚至可以使用标准ORDER BY
进行排序。它会像你提到的那样按顺序返回结果行; 1, 1, 3, 4, 5, 6, 6, 6, 9, 10
。
SELECT idno, name, rank, total_score FROM table_name ORDER BY rank;