Using a single CASE statement in the aggregation funtion
One can use a CASE statement inside an aggregation funtion like SUM() , where CASE statement ( in this case ) is used to decide the condition for a row value to
One can use a CASE statement inside an aggregation funtion like SUM() , where CASE statement ( in this case ) is used to decide the condition for a row value to be included in the sum. And here is the query\n\n```\nSELECT stock_name, SUM(\n                        CASE\n                            WHEN operation=\'BUY\' THEN -price\n                            ELSE price\n                        END) AS capital_gain_loss\nFROM Stocks\nGROUP BY stock_name\n```\n\n\n
['MySQL']