Beginner Friendly Solution | MySQL
\n# Code\n\n# Write your MySQL query statement below\n\nWITH cte1 AS(\nSELECT stock_name,SUM(price) AS "buy" FROM Stocks WHERE operation="Buy" GROUP BY stock_na
\n# Code\n```\n# Write your MySQL query statement below\n\nWITH cte1 AS(\nSELECT stock_name,SUM(price) AS "buy" FROM Stocks WHERE operation="Buy" GROUP BY stock_name\n),\ncte2 AS(\nSELECT stock_name,SUM(price) AS "sell" FROM Stocks WHERE operation="Sell" GROUP BY stock_name\n)\n\nSELECT c.stock_name,c2.sell-c.buy AS capital_gain_loss FROM cte1 c INNER JOIN cte2 c2 ON c.stock_name=c2.stock_name;\n```
['MySQL']