I have a table
Would a simple
GROUP BY solve your issue?
SELECT `symbol`, SUM(IF(transaction_type = 'Debit', `amount` * -1, `amount`)) amount FROM `transaction` GROUP BY `symbol`
Obviously you'd want to adjust your indexes to support this, probably on (