Hi
I have table called Games with columns: Player1Id, Player2Id, Player1Points, Player2Points.
Sample data:
Player1Id Player2Id Player1Points Player2Points
--------- --------- ------------- -------------
John Piter 4 1
John Adam 2 10
Piter Adam 4 2
And I want to have a list with sum of points for each player, like that:
PlayerId Points
-------- ------
John 6
Piter 5
Adam 12
How to achive that in SQL (SQL Server 2008)? And what if I need a sum of points only if some player won a match? Can it be done without using variables, loops etc?