👇 MySQL 2 solutions | very easy 🔥 case or if?
\uD83D\uDE4B\uD83C\uDFFB\u200D\u2640\uFE0F Hello, here are my solutions to the problem.\n### Please upvote to motivate me post future solutions. HAPPY CODING \u
### \uD83D\uDE4B\uD83C\uDFFB\u200D\u2640\uFE0F Hello, here are my solutions to the problem.\n### Please upvote to motivate me post future solutions. HAPPY CODING \u2764\uFE0F\n##### Any suggestions and improvements are always welcome.\n##### Solution 1: If, sum, group by \uD83C\uDFAF\n##### \u2705 Runtime: 411 ms, faster than 97.20% of MySQL \uD83D\uDD25\n```\nselect\n    stock_name,\n    sum(if(operation=\'Buy\', price*(-1), price)) as capital_gain_loss\nfrom stocks\ngroup by 1\n```\n##### Solution 2: case, sum, group by \uD83C\uDFAF\n##### \u2705 Runtime: 441 ms, faster than 89.28% of MySQL \uD83D\uDD25\n```\nselect\n    stock_name,\n    sum(case when operation=\'Buy\' then price*(-1) else price end) as capital_gain_loss\nfrom stocks\ngroup by 1\n```\n##### Two fast solutions, who likes more - case or if? I prefer solution with if \uD83E\uDD37\uD83C\uDFFB\u200D\u2640\uFE0F\n##### If you like the solutions, please upvote \uD83D\uDD3C \n##### For any questions, or discussions, comment below. \uD83D\uDC47\uFE0F
['MySQL']