title: Calculated Column Based on Two Calculated Columns
body: <p>I'm trying to do a rather complicated <code>SELECT</code> computation that I will generalize:</p>
  
  <ol>
  <li>Main query is a wildcard select for a table</li>
  <li>One subquery does a <code>COUNT()</code> of all items based on a condition (this works fine)</li>
  <li>Another subquery does a <code>SUM()</code> of numbers in a column based on another condition. This also works correctly, except when no records meet the conditions, it returns <code>NULL</code>. </li>
  </ol>
  
  <p>I initially wanted to add up the two subqueries, something like <code>(subquery1)+(subquery2) AS total</code> which works fine unless subquery2 is null, in which case <code>total</code> becomes null, regardless of what the result of subquery1 is. My second thought was to try to create a third column that was to be a calculation of the two subqueries (ie, <code>(subquery1) AS count1, (subquery2) AS count2, count1+count2 AS total</code>) but I don't think it's possible to calculate two calculated columns, and even if it were, I feel like the same problem applies.</p>
  
  <p>Does anyone have an elegant solution to this problem outside of just getting the two subquery values and totalling them in my program?</p>
  
  <p>Thanks!</p>