我试图根据他们赢得多少次战斗来对玩家进行排名。这是一个2人游戏,获胜者是玩家核心10的玩家。
在我的播放器数据库中,我有以下内容:
playerID | name
1 Lasse
2 Kevin
4 Brian
我的 playerfight DB:
fightID | playerID | playerScore
1 1 10
1 2 4
2 4 6
2 2 10
etc..
我无法弄清楚如何通过此查询循环不同的playerID。现在使用了playerID 2,但这将根据我的玩家数据库活动ID而改变。
$query = "SELECT name,
(SELECT DISTINCT count(playerScore) FROM playersfight WHERE playerScore='10' and playerID='2') As Wins,
(SELECT DISTINCT count(playerScore) FROM playersfight WHERE playerScore<'10' and playerID='2') As Loses
FROM players WHERE playerID='2'";
$result = $conn->query($query);
我正在寻找的结果应该是:
Name | Win | Loses
Lasse 5 1
Brian 3 2
Kevin 2 2
提前谢谢