MOST EASIEST SOLUTION 🤯 USING CASE AND WHEN
Here we just add a column where buy = - price and sell = price & then take the sum of it while grouping by stock_name\n\'\'\'\nSELECT \n    stock_name,\n    SUM
Here we just add a column where buy = - price and sell = price & then take the sum of it while grouping by stock_name\n\'\'\'\nSELECT \n    stock_name,\n    SUM(CASE WHEN operation = \'Buy\' THEN - price ELSE price END) as capital_gain_loss\nFROM Stocks\nGROUP BY stock_name\n\'\'\'\n
[]