CASE, GROUP BY
\nselect t1.stock_name stock_name,sum(t1.price) capital_gain_loss from \n(select stock_name,operation_day,\ncase\n    when operation = \'Buy\' then -price\n    
```\nselect t1.stock_name stock_name,sum(t1.price) capital_gain_loss from \n(select stock_name,operation_day,\ncase\n    when operation = \'Buy\' then -price\n    else price\nend as price\nfrom Stocks) t1 \ngroup by stock_name;\n```
[]