I have an SQL Server table Table_1 with name, subname, value columns
For each subname i can get the average of the values by the query:
select subname, AVG(value) as avg from Table_1 group by subname;
I also can get the sum of values for each name:
select name, sum(value) as sum from Table_1 group by name;
I need the percentage of each avg row for each of the name, i cant figure this out.
EDIT: Eg. of percent would be — average val1 is x% of the total avg values in a1
select * from Table_1 looks like:
name subname value
a1 val1 20
a1 val2 20
a1 val3 10
a1 val1 40
a1 val2 30
a2 2val3 90
a2 2val1 80
a2 2val2 30
a2 2val3 90
a2 2val1 80
a2 2val1 630
Output:
Useful reading: