simple way to solve this problem
\nselect stock_name,sum(if (operation = "Buy",-price,price)) as capital_gain_loss \nfrom Stocks group by stock_name;\n
```\nselect stock_name,sum(if (operation = "Buy",-price,price)) as capital_gain_loss \nfrom Stocks group by stock_name;\n```
[]