I need to show the running total for each person in my database but I could only get the running total for all of them, so these are my tables on the pic
I already have this query:
SELECT
id,
studno,
if(type=0,amount,0)debit,
if(type=1,amount,0)credit,
if(type=0,@bal:=@bal+amount,@bal:=@bal-amount) runningTotal
FROM
(SELECT id, studno, amount, 0 type from tblPayables
UNION ALL
SELECT id, studno, amount, 1 type from tblPayments)s, (SELECT @bal:=0)b
ORDER BY studno, id, type;
but the thing is I can only come up to this result:
The highlighted number should be 50 since it's for a different studno