hope this fix your issue SQL magic inspired by this answer It doesn't look very pretty but works. Alternatively you may consider creating a db view with the balance select to keep your code a bit cleaner.
How Can Calculate Credits,Debits & Balance in the general ledger?
By : Eyal Askenazi
Date : March 29 2020, 07:55 AM
I wish this helpful for you Balance Not showing proper value
s.debit - s.credit as Balance,
@RunningBalance:= @RunningBalance + s.debit - s.credit RunningBalance
select min(trx_id) trx_id,t.staff_id,
sum(case when trx_type = 'debit' then trx_amount else 0 end) as Debit,
sum(case when trx_type = 'credit' then trx_amount else 0 end) as Credit
from trans t
group by staff_id
order by trx_id
(Select @RunningBalance:=0) rb
order by s.trx_id