Build a billing aging report using CTEs. First CTE computes the age in days of each unpaid bill (status != 'paid') as of '2025-01-01'. Second CTE categorizes: 0-30 days = 'Current', 31-60 = '31-60 Days', 61-90 = '61-90 Days', 91+ = '90+ Days'. Return the aging_bucket and total_amount (sum of amount, rounded to 2). Order by the bucket in the order listed.
Schema
🔑idINT
🔗visit_idINT
amountREAL
insurance_coveredREAL
patient_responsibilityREAL
statusTEXT
billed_atTEXT
paid_atTEXTNULL
postgresql
Run your query to see results
Press Ctrl + Enter to execute