GO FOR ! (TOP - 97.11%)
\n\n\n\n\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\nG
![image](https://assets.leetcode.com/users/images/a13c03af-6e3e-4008-b438-bd8d3b926839_1655739106.5704913.gif)\n\n\n\n\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```
['MySQL']