I need to get a top 100 meds prescribe by a doctor for past 6 month for practice id/location ='0022' : here is my query: I am not sure if this is correct? for practice 0022 there are 367 providers.
Thanks!
select count(medication_name), pm.last_name,pm.first_name,c.meds_id,practice_id,quanity,c.create_timestamp,medication_name,
START_DATE,DATE_STOPPED,DATEPART(MONTH, C.create_timestamp) AS MONTH
from provider pm
join medications C on C.provider_id=pm.provider_id
where C.create_timestamp >= Dateadd(Month, Datediff(Month, 0, DATEADD(m, -6,current_timestamp)), 0) --- from the first day
and practice_id='0022'
group by medication_name,pm.last_name,pm.first_name,c.meds_id,quanity,c.create_timestamp,medication_name,practice_id, > START_DATE,DATE_STOPPED
order by count(C.Meds_id) desc