I have a table that stores a ranking for an online game. This table (Players) has 4 columns (Player_ID, Player_Name, Current_ELO and Player_Status). I want to show the games won/lost as well, but that info is in the Replays table, which has one row per each individual game. I can easily count the number of won games or lost games with the count(*) function:
select Winner, count(*) from Replays group by Winner;
select Loser, count(*) from Replays group by Loser;
However, I cannot find a way to join both tables so my final result is something like:
+-------------+-------------+-----------+------------+
| Player_Name | Current_ELO | Won games | Lost games |
+-------------+-------------+-----------+------------+
| John | 1035 | 5 | 3 |
+-------------+-------------+-----------+------------+
My best guess is this, however returns too many results because I cannot group the "count()" by Winner/Loser individually for each count:
select Player_Name, Current_ELO, Player_Status, count(Winner_Replays.Winner), count(Loser_Replays.Loser) from Players
inner join Replays as Winner_Replays on Winner_Replays.Winner = Players.Player_Name
inner join Replays as Loser_Replays on Loser_Replays.Loser = Players.Player_Name
group by Winner_Replays.Winner order by Current_ELO desc;
Ideally, as some players might have 0 wins or 0 losses, I would like that it returns 0 for those users, if that is possible at all. Thanks!