SQL for Finance: Accounts-Receivable Ageing and a Collections List
<p>Kothari Pack Supplies, a packaging distributor in Pune, sells to seventy-odd businesses on 30 to 60 days' credit, and its bank wants an ageing statement, a collections list and its days sales outstanding as at 30 September before it renews the company's credit limit. The collections spreadsheet can't be trusted: last month it had Farhan chasing a customer who had already paid. Meera Joshi, the accounts manager, decides to build every report as SQL she can re-run each month.</p><p>Across five lessons you build them with her, on a read-only copy of the sales ledger in an in-browser MySQL lab: filters that respect the financial year and cancelled invoices, balances from part payments, TDS and credit notes with LEFT JOINs that don't fan out, days past due with DATEDIFF, ageing buckets with CASE and exact edges, a customer-by-bucket pivot, credit holds that net off money paid on account, a call list ranked with RANK(), a bank statement built with UNION ALL, and a DSO that keeps its decimals. Every lesson you write the query yourself first, then hand the same job to your AI (ChatGPT, Claude, Copilot or Gemini) and learn exactly where it goes wrong. In the capstone your AI writes the final reports from one brief, and you prove every number before it reaches the bank.</p>
Tools: SQL (MySQL), LEFT JOIN and CTEs, Dates with DATEDIFF, CASE and conditional aggregation, Window functions (RANK), Accounts-receivable ageing, AI assistants for SQL