SQL Best Explanation Line-By-Line
Concept:  For each stock_name ( use GROUP BY for collection stock_name )\nAdd +ve value,  if it is of type of "sell" otherwise add -ve value.\n\nSELECT S.stock_
**Concept**:  For each stock_name ( use GROUP BY for collection stock_name )\nAdd +ve value,  if it is of type of "sell" otherwise add -ve value.\n```\nSELECT S.stock_name, \n#the most impotant part, defining condition for SUM\nSUM(CASE WHEN S.operation=\'Buy\' THEN S.price*(-1) ELSE S.price END) AS capital_gain_loss\nFROM Stocks AS S\nGROUP BY stock_name;\n```
['MySQL']