update loan l
inner join (
select LoanId, sum(Amount) as Amount
from loanpayment
where LoanId = pLoanId
) as lp on l.Id = lp.LoanId
set l.CurBalance = OriginalAmount + TermMonths *(OriginalAmount * MonthlyRate/100)
- coalesce(lp.Amount,0)
where l.Id = pLoanId ;
The CurBalance is not being updated when I change the TermMonths. Am I missing something ?
Thanks. I am on mysql 7 and 8.