SQL Solution
select stock_name, SUM(IF(operation = \'Buy\', -1*price, price)) as capital_gain_loss from Stocks group by stock_name;
select stock_name, SUM(IF(operation = \'Buy\', -1*price, price)) as capital_gain_loss from Stocks group by stock_name;
['MySQL']