Very Easy Solution
Easiest solution using if condition.\n```\nselect stock_name, \nsum(if(operation = \'buy\', -price, +price)) as capital_gain_loss\nfrom stocks \ngroup by stock_
Easiest solution using if condition.\n```\nselect stock_name, \nsum(if(operation = \'buy\', -price, +price)) as capital_gain_loss\nfrom stocks \ngroup by stock_name;
[]