PORTFOLIO

(select b.mid, b.symbol, (b.total - s.total) quantity
   from buy_transaction b, sell_transaction s
   where b.mid = s.mid and
         b.symbol = s.symbol and
         (b.total - s.total) > 0)
  union
  (select b.mid, b.symbol, b.total  quantity
   from buy_transaction b
   where not exists (
                select *
                from sell_transaction s
                where b.mid = s.mid and
                      b.symbol = s.symbol))