Faster than 95.17% of MS SQL Server
\nselect stock_name, \ncapital_gain_loss = sum(case when operation =\'Sell\' then price end)\n                    -sum(case when operation = \'Buy\'then price e
```\nselect stock_name, \ncapital_gain_loss = sum(case when operation =\'Sell\' then price end)\n                    -sum(case when operation = \'Buy\'then price end)\nfrom Stocks\ngroup by stock_name\n```
['MS SQL Server']