Write a SQL query to identify members who have completed their loan payments ahead of schedule on Happy Money.
Use the members, loans, and loan_payments tables. Consider only completed loans and posted payments. Treat the latest posted payment date as the actual completion date.
Output
- One row per qualifying member with
member_id, member_name, ahead_of_schedule_loans, and max_days_ahead
- Include only members with at least one completed loan paid before its scheduled end date
- Order by
max_days_ahead descending, then member_id ascending