First let me explain table structure and my required output.
userid date amount
123 2017-01-01 5
123 2017-01-03 2
124 2017-01-04 2
124 2017-01-04 3
123 2017-01-05 -2
Debit transactions are with negative, positive transactions are credit transactions of members. Account statement we can easily made through this query
select date as BookingDate,
if(amount<0,amount,0) as Debit_Amount,
if(amount>0,amount,0) as Credit_Amount,
(@runtot := amount + @runtot) AS Balance
from transactions,
(SELECT @runtot:=0) c
where userid=123
BookingDate Debit_Amount Credit_Amount Balance
2017-01-01 0 5 5
2017-01-03 0 2 7
2017-01-05 -2 0 5
My requirement is to mark each transaction paid or partial paid base on debit transactions with FIFO method. Like this. Is this possible through mysql query or with better algorithm?
userid date amount status
123 2017-01-01 5 partial_paid(-2)
123 2017-01-03 2
124 2017-01-04 2
124 2017-01-04 3
123 2017-01-05 -2
Thanks