I have the below input
The output will be
The Combined Match Played column is the sum of the values of Match Played column of those players. e.g. for Combined Played 1,2 the Combined Match Played value is 10 + 5 = 15. similarly, Combined Runs Made is the sum of the Runs MAde column of the individual players. e.g. for the same example, the Combined Runs MAde column is 200 +100 =300.Thanks
First of all, what you want is combinations not permutations.
The trick here is to generate a recursive cte that gives you all the combinations, summing the matches and runs is a simple next step. The combination cte is controlled by only adding playerids that are greater than the one you started with (
Is the ordering important?: http://www.sqlservercentral.com/blogs/steve_jones/archive/2011/06/07/combinations-and-permutations.aspx