title: How to build this query in postgresql
body: <p><a href="https://i.stack.imgur.com/IO9SL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IO9SL.png" alt="enter image description here"></a></p>
  
  <p>Supposing I have this data. How to query this in such a way that will result to this in an efficient way. It will sum the qty of all OUT less the IN per item.</p>
  
  <p><a href="https://i.stack.imgur.com/okGHT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/okGHT.png" alt="enter image description here"></a></p>