simple if :)
\n# Code\n\nselect stock_name,sum(if(operation=\'Buy\',-(price),(price))) \nas capital_gain_loss from Stocks group by stock_name \n
\n# Code\n```\nselect stock_name,sum(if(operation=\'Buy\',-(price),(price))) \nas capital_gain_loss from Stocks group by stock_name \n```
['MySQL']