MySQL. Simple and very fast solutions with one select
Solution 1.1\n## the one is more simple to understand\n\nselect \n    stock_name,\n    sum(if(operation = \'Sell\', price, 0)) - sum(if(operation = \'Buy\', pri
# Solution 1.1\n## the one is more simple to understand\n```\nselect \n    stock_name,\n    sum(if(operation = \'Sell\', price, 0)) - sum(if(operation = \'Buy\', price, 0)) as capital_gain_loss\nfrom Stocks\ngroup by 1\n```\n# Solution 1.2\n## the one is faster\n```\nselect \n    stock_name, \n    sum(if(operation = \'Buy\', -1, 1) * price) as capital_gain_loss\nfrom stocks\ngroup by 1\n```
['MySQL']