Provider Analytics Path · Mission 7 of 30Easy

Top 10 diagnoses

Use GROUP BY with TRIM to clean trailing whitespace, ORDER BY DESC, and LIMIT

Back to Provider Analytics

The Brief

Dr. Linda NguyenChief Medical Officerclinical-analytics

What are our top 10 most common diagnoses by encounter volume? Use the diagnosis_code field. I suspect there may be duplicates from whitespace issues in the EHR extract — our IT team has flagged this before. Clean it up before you count.

You'll practice

GROUP BYTRIMLIMIT

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

Hints (3)

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

Hint 1

Single-table top-N by aggregate count, with a string-cleaning step before the grouping key.

Hint 2

TRIM the diagnosis code in BOTH the SELECT and the GROUP BY, then ORDER BY count descending and LIMIT to the top slice.

Hint 3

Without TRIM, codes that differ only by trailing whitespace split into separate groups and the count splits with them.