Solution using Case When Statement
select stock_name, sum(CASE \n                       WHEN operation = \'Sell\'\n                       THEN price\n                       ELSE -price\n         
select stock_name, sum(CASE \n                       WHEN operation = \'Sell\'\n                       THEN price\n                       ELSE -price\n                      END) as capital_gain_loss \nfrom Stocks\ngroup by stock_name;
[]