For each active loan, show the loan id, principal, total amount paid so far (total_paid), and the percentage of the principal that has been paid (pct_paid, rounded to 2 decimal places). Join loans to payments. Only include loans with status 'active'. Order by pct_paid descending.
Schema
🔑idINT
🔗customer_idINT
loan_typeTEXT
principalREAL
interest_rateREAL
term_monthsINT
start_dateTEXT
statusTEXT
postgresql
Run your query to see results
Press Ctrl + Enter to execute