All my leetcode problem solves
select stock_name, total_sell - total_buy as capital_gain_loss from ( select stock_name, sum(case when operation = 'Sell' then price else 0 end) as total_sell, sum(case when operation = 'Buy' then price else 0 end) as total_buy from stocks group by stock_name) x order by capital_gain_loss