Skip to main content
All Problems
hard0% acceptance

Patient Visit Summary with Diagnosis Counts and Billing

Using multiple CTEs, build a patient visit summary. For each patient, show: full name, total_visits, distinct_diagnoses (number of unique diagnoses across all visits), total_billed (rounded to 2 decimals), and avg_bill_per_visit (rounded to 2). Only include patients with at least one visit. Order by total_billed descending.

Schema

🔑idINT
first_nameTEXT
last_nameTEXT
date_of_birthTEXT
genderTEXT
emailTEXT
phoneTEXTNULL
blood_typeTEXT
cityTEXT
stateTEXT
🔗insurance_idINTNULL
created_atTIMESTAMP
postgresql

Run your query to see results

Press Ctrl + Enter to execute