title: SQL percentage of averages
body: <p>I have an SQL Server table <code>Table_1</code> with <code>name, subname, value</code> columns</p>
  
  <p>For each subname i can get the average of the values by the query:</p>
  
  <p><code>select subname, AVG(value) as avg from Table_1 group by subname;</code></p>
  
  <p>I also can get the sum of values for each name:</p>
  
  <p><code>select name, sum(value) as sum from Table_1 group by name;</code></p>
  
  <p>I need the percentage of each <code>avg</code> row for each of the <code>name</code>, i cant figure this out.</p>
  
  <p>EDIT: Eg. of percent would be -- average val1 is x% of the total avg values in a1</p>
  
  <p><code>select * from Table_1</code> looks like: </p>
  
  <pre><code>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  
  </code></pre>