title: Weighted average calculation in MySQL?
body: <p>I am currently using the following query to get some numbers:</p>
  
  <pre><code>SELECT gid, count(gid), (SELECT cou FROM size WHERE gid = infor.gid)       
  FROM infor 
  WHERE id==4325 
  GROUP BY gid;
  </code></pre>
  
  <p>The output I am getting at my current stage is the following:</p>
  
  <pre><code>+----------+-----------------+---------------------------------------------------------------+
  | gid      | count(gid)      | (SELECT gid FROM size WHERE gid=infor.gid)                    |
  +----------+-----------------+---------------------------------------------------------------+
  |       19 |               1 |                                                            19 | 
  |       27 |               4 |                                                            27 | 
  |      556 |               1 |                                                           556 | 
  +----------+-----------------+---------------------------------------------------------------+
  </code></pre>
  
  <p>I am trying to calculate the weighted average i.e.</p>
  
  <blockquote>
    <p>(1*19+4*27+1*556)/(19+27+556)</p>
  </blockquote>
  
  <p>Is there a way to do this using a single query?</p>