ลองเอาไป query ดูนะครับ
select a.pdx,i.name,count(a.an) as cc
from an_stat a
left outer join icd101 i on a.pdx=i.code
left outer join patient p on a.hn=p.hn
where a.dchdate between 'yyyy-mm-dd' and 'yyyy-mm-dd'
and p.chwpart = 'xx' and p.amppart='xx' and p.tmbpart='xx'
and p.moopart = 'xx'
and a.pdx not like 'z%'
group by a.pdx
order by count(a.an) desc
limit 10