1393. Capital Gain/Loss | Mysql | Easy Solution
select stock_name,sum(\ncase \n    when operation = \'Buy\' then -price\n    when operation = \'Sell\' then price\n    end\n) AS capital_gain_loss\n\nFrom Stock
select stock_name,sum(\ncase \n    when operation = \'Buy\' then -price\n    when operation = \'Sell\' then price\n    end\n) AS capital_gain_loss\n\nFrom Stocks group by stock_name;
['MySQL']