Find Three-Way Match Exceptions Between POs, Receipts and Invoices
Last updated: November 29, 2026
Quick Overview
Write SQL that compares purchase order lines, goods receipts and invoice lines and returns every PO line where the billed quantity exceeds what was received or ordered, or the billed unit price differs from the PO price by more than 1%.
PwC
November 29, 20260
0
0 solved
Write SQL that compares purchase order lines, goods receipts and invoice lines and returns every PO line where the billed quantity exceeds what was received or ordered, or the billed unit price differs from the PO price by more than 1%.
Procure-to-pay testing is a staple of PwC audit and advisory work, and the three-way match is the control at its center. A phone screen uses it to see whether a candidate pre-aggregates before joining and handles missing receipts correctly.
What the Interviewer Expects
- Aggregate receipts and invoices to PO line grain before joining
- Use a LEFT JOIN so lines with no receipt still appear
- Treat missing receipts as zero received
- Apply a relative price tolerance
- Label the exception type for reviewers
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 report all exception types for a line rather than only the first?
- What if invoices reference the PO only at header level, not line level?
- How would you handle partial deliveries that arrive after the invoice?
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
purchase_orders(po_id, line_no, item_id, qty_ordered, unit_price), goods_receipts(receipt_id, po_id, line_no, qty_received) with possibly many receipts per line, and `invoice_lines(invoice_id, po_...
Approach
Joining raw receipts to raw invoices fans out (two receipts times two invoices gives four rows and doubles the sums), so I sum receipts and invoices per (po_id, line_no) first in CTEs. Then join PO ...