Healthcare Analytics Path · Mission 7 of 25Easy

Top 10 diagnoses

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

Back to Healthcare 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 available

fact_encounters

Hints (3)

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

Hint 1

The diagnosis codes in `fact_encounters` may have trailing spaces — raw grouping will split what should be one code into two

Hint 2

Wrap the code in the function that strips whitespace, then group and count as usual. Only keep the top 10

Hint 3

`SELECT ___(diagnosis_code) AS diagnosis_code, COUNT(*) AS encounter_count FROM fact_encounters GROUP BY ___ ORDER BY ___ DESC LIMIT ___`