Provider Analytics Path · Mission 16 of 25Hard

Rank specialties by encounter volume

Use RANK() window function with data normalization

Back to Provider Analytics

The Brief

Dr. Linda NguyenChief Medical Officerclinical-analytics

Rank each medical specialty by total encounter volume. Normalize specialty names so 'Cardiology' and 'cardiology' aren't separate. Show specialty, encounter count, and rank. I need to know where to focus our recruiting — if Cardiology is our busiest specialty, we need another cardiologist.

You'll practice

RANK()LOWER()Window functions

Tables & columns available

fact_encountersfact10 columns
ColumnTypeKey
encounter_idINTPK
patient_idINTFK → dim_patients
provider_idINTFK → dim_providers
department_idINTFK → dim_departments
admit_dateTEXT
discharge_dateTEXT
diagnosis_codeTEXT
diagnosis_descriptionTEXT
encounter_typeTEXT
discharge_dispositionTEXT
dim_providersdim7 columns
ColumnTypeKey
provider_idINTPK
first_nameTEXT
last_nameTEXT
specialtyTEXT
department_idINTFK → dim_departments
hire_dateTEXT
is_activeINT

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

Specialty lives in `dim_providers`, volume in `fact_encounters`. Casing inconsistency will split specialties if you don't normalize

Hint 2

Group by the normalized specialty, count encounters, then add a rank column via a window function that orders by that count

Hint 3

`SELECT LOWER(p.specialty) AS specialty, COUNT(*) AS encounter_count, ___() OVER (ORDER BY COUNT(*) ___) AS rank FROM fact_encounters e JOIN dim_providers p ON ___ GROUP BY ___`