Write SQL to Flag Overdue Net 60 Invoices by Retailer
Last updated: November 29, 2026
Quick Overview
Given an orders table with retailer, shipped date and amount, and a payments table of amounts paid per order, write SQL that lists every retailer with an outstanding balance past its net 60 due date as of a given date, along with the overdue amount and the oldest days past due.
Faire
November 29, 20260
0
0 solved
Given an orders table with retailer, shipped date and amount, and a payments table of amounts paid per order, write SQL that lists every retailer with an outstanding balance past its net 60 due date as of a given date, along with the overdue amount and the oldest days past due.
Collections and risk teams on a terms-based wholesale marketplace need a daily view of who is late and by how much. The interviewer checks joins with pre-aggregation, date arithmetic, handling partial payments and NULLs, and avoiding fan-out.
What the Interviewer Expects
- Aggregate payments per order before joining
- Compute due date as shipped date plus 60 days
- Treat missing payments as zero with COALESCE
- Filter to orders past due with positive remaining balance
- Aggregate to retailer with sum and max days past due
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you bucket overdue balances into 1 to 30, 31 to 60 and 60 plus days?
- How would you make this incremental for a daily pipeline?
- How do returns or credits change the calculation?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
orders(order_id, retailer_id, shipped_at DATE, amount_cents); payments(payment_id, order_id, paid_at DATE, amount_cents). Terms start at shipment. An order can have several partial payments or non...
Approach
Pre-aggregate payments made on or before :as_of per order so the join cannot duplicate order rows. Left join to orders, compute remaining balance, keep rows where the due date has passed and the bal...