title: How to Perform Subtraction in SQL query based on some conditions?
body: <p>I want to sum up <code>qty*price</code> where type is 'in' and then subtract the sum of <code>qty*price</code> where type is 'out'. Something like this.
  <code>SELECT cid, name, SUM(paid_amt), (SELECT SUM(qty*price) WHERE type = 'in' - SELECT SUM(qty*price) WHERE type = 'out'), type FROM</code>transactions<code>GROUP BY cid</code>
  Here's is my SQL query. </p>