It looks like you're not aggregated enough. Each field in your GROUP represents a field for aggregation in conjunction with others. Thus, it will only show you the diagnosis by id, by patient, by diagnosis. Not very helpful.
To get the most common diagnosis, remove id and patient_id from the group:
select count(diagnosis) from dbo.diabetes_rx_tracker group by diagnosis order by count(diagnosis) desc
To get the most common codes for all identifiers, remove patient_id from the group and select:
select diagnosis, id, count(1) as CodeCount from dbo.diabetes_rx_tracker group by diagnosis, id order by count(diagnosis) desc
UPDATE: Based on your new criteria, this is what you want.
select id, diagnosis, ct from ( select row_number() OVER (PARTITION BY id ORDER BY count(diagnosis) desc ) as rn, count(diagnosis) as ct, diagnosis, id from dbo.diabetes_rx_tracker group by id, diagnosis ) ranked where rn = 1 order by CT desc
source share