I have a table named games:
id player_a_id player_b_id player_a_result player_b_result turn
1 1 2 1 0 1
2 3 4 1 0 1
3 1 3 1 0 2
I am trying to write a SQL query that will make a rating list of the table. Like this:
player_id total score
1 2
2 0
3 1
4 0
I am not sure how to write the sql. Some help would be great!
This is what I’m guessing you’re after. This creates a subquery (the stuff in parens()) that combines (UNION) players a and b into one set, then groups by player and sums the results.