MySQL Solution
Code\n\nSELECT stock_name, SUM(\n    CASE\n        WHEN operation = \'Buy\' THEN -price\n        ELSE price\n    END\n) AS capital_gain_loss\nFROM Stocks\nGROUP
# Code\n```\nSELECT stock_name, SUM(\n    CASE\n        WHEN operation = \'Buy\' THEN -price\n        ELSE price\n    END\n) AS capital_gain_loss\nFROM Stocks\nGROUP BY stock_name\n```
['Database', 'MySQL']