Easy solution of Capital gain/loss
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nSelecting unique stock_
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSelecting unique stock_name \'s and summing over sell and buy and naming the column as capital_gain_loss \nFROM stocks\nGrouping them according stock_name\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nSELECT DISTINCT stock_name, SUM(CASE WHEN operation=\'Buy\'THEN -price \nELSE price \nEND) AS capital_gain_loss # Write your MySQL query statement below\nFROM Stocks\nGROUP BY stock_name\n```
['MySQL']