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
Data Manipulation (SQL/Python)
Data Engineer
EvenUp
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

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
SQL joins
Aggregation
Window functions
NULL handling
Fan-out
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions