Suppose SQL Server had the following table:
grp: val: criteria: a 1 1 a 1 1 b 1 1 b 1 1 b 1 1 c 1 1 c 1 1 c 1 1 d 1 1
Now I want to get a result that will be basically:
Select grp, val / [sum(val) for all records] grouped by grp where criteria = 1
So, considering the following:
Sum of all values = 9 Sum of values in grp(a) = 2 Sum of values in grp(b) = 3 Sum of values in grp(c) = 3 Sum of values in grp(d) = 1
The output would be as follows:
grp: calc: a 2/9 b 3/9 c 3/9 d 1/9
What would my SQL look like?
Thanks!!
source share