Outstanding Provider Balances Per Case From Bills And Payments
Last updated: November 29, 2026
Quick Overview
Using tables of medical bills, payments with contractual adjustments, and providers, write SQL that returns every provider on every case who still has an outstanding balance, ranked by balance within the case.
EvenUp
November 29, 20260
0
0 solved
Using tables of medical bills, payments with contractual adjustments, and providers, write SQL that returns every provider on every case who still has an outstanding balance, ranked by balance within the case.
Outstanding provider balances drive lien negotiations and the medical damages section of a personal injury demand, so EvenUp's data teams routinely roll bills and payments up to the case level. The screen checks join fan-out awareness, NULL handling and window functions.
What the Interviewer Expects
- Pre-aggregates payments per bill before joining to avoid fan-out
- Uses LEFT JOIN plus COALESCE so unpaid bills still count
- Excludes voided bills
- Computes balance as billed minus paid minus adjustments
- Ranks with a window function partitioned by case
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 also show the date of the oldest unpaid service per provider?
- What changes if a payment can be split across several bills?
- How do you detect payments recorded against bills from a different case?
- Return only the top two balances per case.
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
bills(bill_id, case_id, provider_id, date_of_service, billed_cents, is_voided), payments(payment_id, bill_id, payer_type, paid_cents, adjustment_cents) with zero or more rows per bill, `providers(...
Approach
Aggregate payments to one row per bill first. Joining raw payments to bills and then summing billed_cents would multiply a bill's amount by its number of payments. Then left join bills to that aggre...