MySQL Simple and Clean Solution
Please Upvote if it helped you !!!\n\nselect stock_name,sum(\n\tcase\n\t\twhen operation=\'Buy\' then -price\n\t\telse price\n\tend) as capital_gain_loss\nfrom 
**Please Upvote if it helped you !!!**\n```\nselect stock_name,sum(\n\tcase\n\t\twhen operation=\'Buy\' then -price\n\t\telse price\n\tend) as capital_gain_loss\nfrom stocks \ngroup by stock_name;\n```
['MySQL']