Beats 94%- MySQL Solution-CASE
Code\n\nselect stock_name,\nsum(case when operation=\'sell\' then price end) - sum(case when operation=\'buy\' then price end) as capital_gain_loss\nfrom stocks
# Code\n```\nselect stock_name,\nsum(case when operation=\'sell\' then price end) - sum(case when operation=\'buy\' then price end) as capital_gain_loss\nfrom stocks\ngroup by stock_name\n```
['MySQL']