title: In Postgres, how do I COUNT and WHERE in the same query, then do math on result?
body: <p>I have a large DB of <code>SALES_ORDERS</code>, that I need to determine the % each <code>SELLING_AGENT</code> had in the <code>ORDER</code>.</p>
  
  <p>Learning postgresql, and this is just a sample, of ~500k rows of data.  Each <code>ORDER#</code> could be composed of dozens of <code>SALE_ITEM</code>s (but only composed of <code>'SALE_ITEM_1'</code> and <code>'SALE_ITEM_2'</code>).</p>
  
  <p>I thought I could try doing a SUM SELECT something like this: </p>
  
  <pre><code>    SELECT (SUM(sale_item_1)+sum(sale_item_2)) as total_person_sale
      FROM SALES_ORDER
      WHERE orderNumber LIKE orderNumber
      GROUP by SELLING_AGENT
  </code></pre>
  
  <p>But clearly I'm not grasping the WHERE statement use to count similar</p>
  
  <p>The hope is to fill out the final column, like this: 
  selling agent:</p>
  
  <pre><code>    selling agent:  Order#  Sale_item_1 Sale_item_2 %_of_TOTAL_order
      jim              abc    $1.00       $2.00       14.29%
      steve            abc    $3.00       $4.00       33.33%
      carl             abc    $5.00       $6.00       52.38%
      carl             def    $7.00       $8.00       31.25%
      steve            def    $9.00       $9.00       37.50%
      jim              def    $8.00       $7.00       31.25%
      steve            ghi    $6.00       $5.00       61.11%
      patty            ghi    $4.00       $3.00       38.89%
  </code></pre>