✅✅MySQL || Two Approaches || Case || If-else|| Group By||Easy to Understand
CASE:\n\nselect stock_name,sum(\n    case \n    when operation=\'sell\' then price\n    else -price\n    end\n    ) as capital_gain_loss \nfrom Stocks\ngroup by
**CASE:**\n```\nselect stock_name,sum(\n    case \n    when operation=\'sell\' then price\n    else -price\n    end\n    ) as capital_gain_loss \nfrom Stocks\ngroup by stock_name;\n```\n\n**IF-ELSE:**\n```\nselect stock_name,sum(if(operation=\'sell\',price,-price)) \nas capital_gain_loss \nfrom Stocks\ngroup by stock_name;\n```
['MySQL']