simple SUM
Upvote if you feel it easy :)\n\nSELECT stock_name, SUM(IIF(operation = \'Sell\', 1, -1) * price) AS capital_gain_loss\nFROM Stocks\nGROUP BY stock_name;\n
**Upvote if you feel it easy :)**\n```\nSELECT stock_name, SUM(IIF(operation = \'Sell\', 1, -1) * price) AS capital_gain_loss\nFROM Stocks\nGROUP BY stock_name;\n```
['MS SQL Server']