MySQL Easy solution
\n# Write your MySQL query statement below\nselect\n    stock_name,\n    sum(if(operation=\'Buy\', -price, price)) as capital_gain_loss\nfrom stocks\ngroup by 1
```\n# Write your MySQL query statement below\nselect\n    stock_name,\n    sum(if(operation=\'Buy\', -price, price)) as capital_gain_loss\nfrom stocks\ngroup by 1\n```\n#UPVOTE IF U FIND IT USEFUL
['MySQL']