I have a table that roughly looks like the following:
| winner_name | loser_name |
|---|---|
| Person A | Person B |
| Person A | Person C |
| Person B | Person A |
| Person C | Person B |
I'm trying to return a table that looks like the following:
| player_name | number_wins | number_losses |
|---|---|---|
| Person A | 2 | 1 |
| Person B | 1 | 2 |
| Person C | 1 | 1 |
I can't quite figure out how to get there. I have been able to write a query that returns player_name and either number_wins or number_losses, but not both.
SELECT winner_name AS player_name, COUNT(*) AS number_wins
FROM my_table
GROUP BY player_name
I have looked into using procedures, functions, and subqueries to do this but I haven't found the right solution yet. Any direction would be helpful.