very easy CASE
\nSELECT stock_name, \n\tSUM(CASE WHEN operation = \'Buy\' THEN -price ELSE price END) AS capital_gain_loss\nFROM Stocks\nGROUP BY stock_name\n
```\nSELECT stock_name, \n\tSUM(CASE WHEN operation = \'Buy\' THEN -price ELSE price END) AS capital_gain_loss\nFROM Stocks\nGROUP BY stock_name\n```
['MS SQL Server']