title: How can I get three function for one field in different states
body: <p>I have a <code>product</code> table and I want to get sum of qty is different states</p>
  
  <p>Here is my table ...</p>
  
  <pre><code>kind|  qty  
  1   |  150
  8   |  122
  1   |  177
  3   |  60
  8   |  66
  ...
  </code></pre>
  
  <p>How can I get this statement </p>
  
  <pre><code>select sum(qty) when kind=1, sum(qty) when kind=8, sum(qty) when kind=3, 
  sum1+sum2-sum3 from mytable
  </code></pre>
  
  <p>The last row I want to get calc field from this statement in my sql</p>
  
  <pre><code>sum1+sum2-sum3 from mytable
  </code></pre>
  
  <p>and the result will be </p>
  
  <pre><code>sum1 , sum2, sum3, calc
  </code></pre>