I am trying to use an aggregate function in MySQL to return the balance of an account. However I keep getting an error an it's driving me nuts!
SELECT cast(sum((number_sold - number_bought) * price) as unsigned) as 'Balance'
FROM transactions
This returns:
#2014 - Commands out of sync; you can't run this command now
Here's an SQLfiddle: http://sqlfiddle.com/#!2/26297/1
Any help appreciated!