Very very easy question LOL
Do inner join and subtract one from another\n\nselect sell.stock_name, (capital_loss-capital_gain) as capital_gain_loss  from \n(select stock_name, sum(price) a
Do inner join and subtract one from another\n```\nselect sell.stock_name, (capital_loss-capital_gain) as capital_gain_loss  from \n(select stock_name, sum(price) as capital_loss from stocks where operation="Sell" group by stock_name) as sell inner join\n(select stock_name, sum(price) as capital_gain from stocks where operation="Buy" group by stock_name) as buy on sell.stock_name = buy.stock_name\n```\n\nAnother approach using if-else statement\n```\nSELECT stock_name, SUM(CASE WHEN operation = "Buy" THEN price * (-1) ELSE price END) AS capital_gain_loss\nFROM Stocks\nGROUP BY stock_name\n```
[]