How to read each row until get to the point to determine if it is paid or overpaid or partially paid
How do I read each line to determine if the customer has fully paid or partially paid or never paid?
I would like the code to read every line of each customer's bill until I find the TOTAL_PAYMENT_AMT = TOTAL_DUE. If found, then mark it as paid, if not found, read the next line until I found the TOTAL_PAYMENT_AMT <> 0 and TOTAL_PAYMENT_AMT + TOTAL_ADJ_AMT < TOTAL_DUE then mark it as partially paid or if the TOTAL_PAYMENT_AMT +TOTAL_ADJ_AMT > TOTAL_DUE, then mark it as paid.
For customer 111, the bill is fully paid -13129.54 from reading the first line. But for customer 222, the bill has not paid until the 2nd month for the amount of -27000.00 and for cumster 333, the bill is paid partially the 2nd and the 3rd month. For customer 444, the bill has never paid.(negative # means paid, positive # means extra amount charged)
This is the result I got from joining tables using rank over()