title: SQL - Subtract the sum of certain records from the total
body: <p>Given the following table</p>
  
  <pre><code>ITEMID  | TYPE          | QTY |
  -----------------------
  ...
  134     |TOTALINDEPOT   | 169 |
  134     |UNUSED         |  70 |
  134     |FAULTY         |  15 |
  134     |DAMAGED        |   1 |
  134     |DELAYED        | 100 |
  ...
  </code></pre>
  
  <p>What is an efficient way to retrieve the quantity of available items with id 134 (excluding these of delayed type)? Result is 83 => (169-(70+15+1)).
  I implemented it with <code>(SELECT qty FROM tableA WHERE type='TOTALINDEPOT' AND itemid='134') - (SELECT SUM(qty) ... WHERE TYPE IN ('UNUSED', 'FAULTY', 'DAMAGED')) AND itemid='134'</code>, but looking for something more elegant.</p>