title: Computing percentages within subtotals
body: <p>I am trying to compute percentages of a subtotal in one sql statement. This requires using a subquery, but thus far not able to adapt SAS's <a href="http://support.sas.com/documentation/cdl/en/sqlproc/63043/HTML/default/viewer.htm#n112pviu616u5rn1uileli1b03zb.htm" rel="nofollow">example</a>. </p>
  
  <p>Requires 2 steps:</p>
  
  <ol>
  <li>Compute subtotal of TotalCargo by LoadArea.</li>
  <li>Sum the subtotals and divide each LoadArea's subtotal by sum.</li>
  </ol>
  
  <p>Divide subtotal by sum of all the subtotals.</p>
  
  <pre><code> ShipmentID   LoadArea    TotalCargo
   1            BRZ         200000
   2            BRZ         250000
   3            AG          200000
   4            AG          250000 
  
  
  
   End result:
   LoadArea  TotalCargo  Vol_share
   AG        450000      .5
   BRZ       450000      .5     
  </code></pre>