title: SQL Query - GROUP BY , PARTITION BY
body: <p>This is my first post and I am new to SQL </p>
  
  <p>I have a table like</p>
  
  <pre><code>H     Amount    Count      ID 
  
  h1      2         1         x
  h2      3         2         x
  h3      5         3         x
  h1      3         3         x
  h1      1         5         y
  h2      3         2         x
  h3      1         1         x
  h3      2         3         y
  h2      5         5         y
  </code></pre>
  
  <p>and I want SUM(Amount*Count) of each H group based on id / Total SUM(Amount*Count) in that H group</p>
  
  <p>i.e</p>
  
  <pre><code>H     value       ID
  
  h1     11/16       x                     value =  (2*1+3*3)/2*1+3*3+1*5 
  h1      5/16       y                     value =   1*5/ 2*1+3*3+1*5 
  h2      12/37      x 
  h2      25/37      y 
  h3      16/22      x 
  h3       6/22      y
  </code></pre>
  
  <p>My aim is  to group by H and then on EACH GROUP I have to do  - Sum(average*count) Over(partition by ID) / Sum(average*count)</p>
  
  <p>but I am not able to write such query can you guys please help me.
   And sorry about the formatting
   Thanks</p>