Explain how you would perform common SQL database operations for an i2c payment or banking workflow.
Write a PostgreSQL query that summarizes January 2025 settled debit activity for every active account and includes accounts with no qualifying transactions. Join account ownership information, exclude non-settled or non-debit activity, and handle missing transaction amounts safely.
Output
- One row per active account, with
account_id, customer_name, total_debit_amount, settled_debit_count, and latest_transaction_date
- Include accounts with no qualifying transactions, using zero totals and a NULL latest date
- Sort by
total_debit_amount descending, then account_id ascending