MySQL – Ledger Debit/Credit Query

Perhaps you may need a ledger type query that can display a running total like the one on a bank statement.

SELECT a.*, (@running_balance:[email protected]_balance+(a.credit-a.debit)) AS 'balance' FROM ledger a 
JOIN (SELECT @running_balance := 0) b 
WHERE a.id_user = ? AND a.account_type = ? AND a.year = ?