Using IF() instead of CASE
Query\n\nSELECT stock_name,\nSUM(IF(operation = \'Buy\',-price,price)) AS \'capital_gain_loss\'\nFROM Stocks\nGROUP BY stock_name;\n
# Query\n```\nSELECT stock_name,\nSUM(IF(operation = \'Buy\',-price,price)) AS \'capital_gain_loss\'\nFROM Stocks\nGROUP BY stock_name;\n```
['MySQL']