title: SQL: Subtract two columns
body: <pre><code>select content_type_code_id 
      , ABS(price) AS price
      , SUM(case when price &gt;= 0 THEN 1 ELSE 0 END) AS debits
      , SUM(case when price &lt; 0 THEN 1 ELSE 0 END) AS credits
  from dbo.transaction_unrated  
  where transaction_date &gt;= '2012/05/01'
        and transaction_date &lt; '2012/06/01'
        and content_provider_code_id in (1)
  group by content_type_code_id, ABS(price) 
  ORDER BY ABS(price) ASC  
  </code></pre>
  
  <p>The above query produces the following output:</p>
  
  <pre><code>content_type_code_id    price   debits  credits
  1                      0.00      317    0
  1                      0.99      178    1
  1                      1.99      786    1
  </code></pre>
  
  <p>But I want something like this:</p>
  
  <pre><code>content_type_code_id    price   debits  credits NetCount
      1                      0.00      317    0       317 
      1                      0.99      178    1       177 
      1                      1.99      786    1       785
  </code></pre>
  
  <p>Where NetCount = (debits - credits)</p>
  
  <p>When I try to create another column for that I get an error.  </p>