I have a table in sql which has the following attributes:
- The first payment of a loan payment (StartPayment)
- The next date of a loan payment (NextPayment)
- The total number of payments in the loan (NumberOfPayments)
- The final payment of the loan (FinalPayment)
- The amount each loan payment is (Amount)
- The primary key (LoanID)
What I wish to do is work out the remainder of payments of a particular loan and multiply that by the amount each loan payment is for all loans in the database. However I'm not sure what the best way to do this is a query would be. I have an example of a loan attribute below
INSERT INTO loans VALUES
{
'2021-09-25','2021-12-25', 10, '2022-07-25', 160.00);
}
Basically what I want is to calculate the remaining amount of money left to pay, which would be the months left between the next payment to the final payment, and multiply that by amount. I'm not sure however on how to structure my query for this problem and whether or not this is doable. Is there a way to do this is sql?