I have a few tables:
users - id
users_matches - user_id, match_id, team
matches - id, winner
I'd like to count how many wins, losses, and ties a user has. team
is an integer that could be 1 or 2. winner
is also an integer, but it can be 1 (team 1 wins), 2 (team 2 wins), or 3 (tie).
I'm not sure how to mix a grouped count
with a nested query in Postgres.