title: Sql Case Column 1 and Column same value then apply calculation
body: <p>I would like apply calculation in CASE Statement, but the result is not I'm expected and I'm not sure how to apply the query to filter date(depend on month). What is the problem with my query?? Please help... Thank you</p>
  
  <p>this is my query</p>
  
  <pre><code>SELECT DISTINCT a.SERVICE_CODE, 
         CASE WHEN
             b.SERVICE_CODE IS NULL THEN a.AMT ELSE  SUM (a.AMT) - SUM(b.AMT) END AS TOTAL_AMT
         FROM Table a
   LEFT OUTER JOIN Table b ON (a.SERVICE_CODE = b.SERVICE_CODE)
   WHERE  b.SERVICE_CODE &gt;='3000' AND c.SERVICE_CODE &gt;='3000'
  </code></pre>
  
  <p>Table a</p>
  
  <pre><code>Invoice_No               date          Service_code     Amt
  001                     1/7/2014       6000             300
  002                     1/8/2014       6003             700
  003                     5/8/2014       6003             100
  004                     10/8/2014      6005             1000
  </code></pre>
  
  <p>Table b</p>
  
  <pre><code>Credit_No                 date          Service_code     Amt
  c100                     1/7/2014       6000             300
  c200                     13/8/2014      6003             700
  </code></pre>
  
  <p>Desired output</p>
  
  <pre><code>Service_code              Total_Amt
  6003                      100
  6005                      1000
  </code></pre>
  
  <p>Thank you</p>