我需要一些有关 MySQL 查询的帮助。我正在尝试使用 WHERE 子句对参与者进行排名。所以,我想分别对新手、中级和经验者进行排名。例如:
Rank Name Grade Type
----------------------------------
1 Bob 98 Novice
2 Jill 88 Novice
3 Jimmy 42 Novice
1 Mark 87 Intermediate
2 Scott 85 Intermediate
3 Jim 77 Intermediate
1 Jane 90 Advanced
2 John 89 Advanced
3 Josh 87 Advanced
我试过了:
SET @rank=0;
(SELECT @rank:=@rank+1 AS rank, name, grade, type FROM myTable WHERE type='novice' ORDER BY grade DESC)
UNION ALL
(SELECT @rank:=@rank+1 AS rank, name, grade, type FROM myTable WHERE type='intermediate' ORDER BY grade DESC)
UNION ALL
(SELECT @rank:=@rank+1 AS rank, name, grade, type FROM myTable WHERE type='experienced' ORDER BY grade DESC)
我想我需要以某种方式重新设置排名。也许我还有另一个问题?