🌟 PostgreSQL solution
\n# Code\n\nSELECT stock_name,\n        SUM((CASE\n                WHEN operation = \'Buy\' THEN -price\n                ELSE price\n            END)) AS capita
\n# Code\n```\nSELECT stock_name,\n        SUM((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\nIf it was useful don\'t hesitate to upvote, comment \uD83C\uDF20 Or keep it in favorite \uD83C\uDF1F\n![Upvote invitation](https://github.com/MathieuSoysal/CROUS-assistant-Collector/assets/43273304/b801cf95-dcda-4733-ada2-939f5fcb29e0)
['PostgreSQL']