title: When getting sums in PostgreSQL, how do I skip over a row containing a null (or nil) value?
body: <p>My dataset:</p>
  
  <pre><code>item_category,year,price
  "Bacon",1910,0.255
  "Bacon",1911,0.247
  "Bacon",1912,0.244
  "Bacon",1913,0.27
  "Bread",1913,0.056
  "Bread",1914,0.063
  "Bread",1915,0.07
  "Bread",1916,0.073
  </code></pre>
  
  <p>My code so far:</p>
  
  <pre><code>SELECT
      string_agg(DISTINCT item_category, ' and ' ORDER BY item_category) AS items,
          year,
          sum(avg_yr_value) AS price
  FROM
      earnings_and_prices
  WHERE
      (item_category = 'Bacon' OR item_category = 'Bread')
  GROUP BY
      year
  ORDER BY
      year
  </code></pre>
  
  <p>My output (I use the Ruby gem sequel, so this is in Hash format):</p>
  
  <pre><code>{:items=&gt;"Bacon", :year=&gt;1910, :price=&gt;0.255}
  {:items=&gt;"Bacon", :year=&gt;1911, :price=&gt;0.247}
  {:items=&gt;"Bacon", :year=&gt;1912, :price=&gt;0.244}
  {:items=&gt;"Bacon and Bread", :year=&gt;1913, :price=&gt;0.326}
  {:items=&gt;"Bacon and Bread", :year=&gt;1914, :price=&gt;0.338}
  {:items=&gt;"Bacon and Bread", :year=&gt;1915, :price=&gt;0.339}
  {:items=&gt;"Bacon and Bread", :year=&gt;1916, :price=&gt;1.017}
  </code></pre>
  
  <p>I only want the years which contain prices for both bacon and bread. How do I do this?</p>