[MySQL] IF Statement, NO CASE Statement
Since the problem promises that each sell operation has a buy operation or vice versa, we can only judge whether the operation is sell or not.\n\n\nSELECT\n    
Since the problem promises that each sell operation has a buy operation or vice versa, we can only judge whether the operation is sell or not.\n\n```\nSELECT\n    stock_name,\n    SUM(\n        IF(operation=\'Sell\',1,-1)\n        * price\n    )\n    AS capital_gain_loss\nFROM Stocks\nGROUP BY stock_name;\n```\n
[]