Is there a way to convert the following into a query without subqueries (or with a lesser number of subqueries) in order to make it faster.
select ( +(select sum(coalesce(quantity,0)) from transaction where
buyer_number = 101 and stock_id = 22 and status = \'bought\')
-(select sum(coalesce(quantity,0)) from transaction where
seller_number = 101 and stock_id = 22 and status = \'sold\')
) as balance_primary,
( +(select sum(coalesce(quantity,0)) from transaction where
buyer_number = 101 and stock_id = 22 and status = \'received\')
-(select sum(coalesce(quantity,0)) from transaction where
seller_number = 101 and stock_id = 22 and status = \'gifted\')
) as balance_secondary