如何从包含金银牌和铜牌的牌桌中找到个人排名

时间:2016-03-20 22:07:29

标签: mysql

如何从下表中找到个人排名,对于相同的排名,排名也应该相同,就像奥运奖牌表一样。

表格如下:

          Gold Slvr B   Total
India      44   0   0   0
Australia   7   0   0   0
Pakistan    5   0   1   6
Zimbabwe    2   2   2   5
Afghanistan 2   0   0   0
NewZealand  1   1   0   2
England     1   1   0   2

2 个答案:

答案 0 :(得分:1)

你有可能想要这样的东西:

ORDER BY MAX(Gold) DESC, MAX(Slvr) DESC, MAX(B) DESC

要在每行中加入排名,请参阅Rank function in MySQL

答案 1 :(得分:0)

得到如下答案: -

选择排名,电子邮件,tgolds,tsilver,tbronze(SELECT email,tgolds,tsilver,tbronze,@curRank:= @curRank + 1 AS rank FROM results p,(SELECT @curRank:= 0)r ORDER BY tgolds desc,tsilver desc,tbronze desc,tmedal desc,date asc)as k where k.email ='$ _SESSION [email]'“;