如何根据获胜/损失列获取PHP中Mysql查询的百分比

时间:2014-11-20 01:38:40

标签: php mysql

我需要此Rank查询还要有一个IF语句来计算赢/输,并将百分比放在@percentage变量中。我不知道如何将排名查询与百分比查询相结合。

mysql_query("SELECT name, wins, losses, level, xp, @curRank := @curRank + 1 AS rank 
FROM teams p, (SELECT @curRank := 0) r 
WHERE `console` = 3 AND `game` = 23 AND `laddertype` = 1 
ORDER BY xp DESC");

1 个答案:

答案 0 :(得分:0)

SELECT name,wins,loss,level,xp,wins AS W,loss AS L,TRUNCATE(wins / IF(wins = 0,1,wins + loss)* 100,0)AS PCT,@curRank:= @curRank + 1 AS排名来自团队p,(SELECT @curRank:= 0)r WHERE console = 3 AND game = 23 AND laddertype = 1 ORDER BY xp DESC;