troubleshooting Question

SQL query top 10 orders per provider

Avatar of biotec
biotec asked on
Microsoft SQL ServerSQL
11 Comments2 Solutions66 ViewsLast Modified:
I have a query below that gives me top diagnoses (orders) but can't seem to get it per provider_id. I need top 10 diagnoses done for each provider so group by provider and show each providers' top 10 for the year. Any help is appreciated. Thanks

select TOP 10 e.icd9cm_code_id, e.icd9cm_code_desc, pm.provider_id, COUNT(e.icd9cm_code_id) as times_used
FROM encounter_diags e
inner join patient_encounter pe on e.enc_id = pe.enc_id
inner join provider_mstr pm on pe.rendering_provider_id = pm.provider_id
WHERE pe.enc_timestamp >= '20150101' AND pe.enc_timestamp  < '20160101'
--and pm.provider_id = '01A6E951-730F-4ECB-901E-BB4380EEE233'
GROUP BY pm.provider_id, e.icd9cm_code_id, e.icd9cm_code_desc 
ORDER BY COUNT(icd9cm_code_id) DESC
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros