select a.main_pdx,a.pdx,count(a.main_pdx) as pdx_count,count(b.sex) as sex1,count(c.sex) as sex2,
count(g.age_y) as '0-4',count(h.age_y) as '5-9',count(j.age_y) as '10-14',count(k.age_y) as '15-19',
count(l.age_y) as '20-24',count(m.age_y) as '25-29',count(n.age_y) as '30-34',count(o.age_y) as '35-39',
count(p.age_y) as '40-44',count(q.age_y) as '45-49',count(r.age_y) as '50-54',count(s.age_y) as '55-59',
count(t.age_y) as '60-64',count(u.age_y) as '65-69',count(v.age_y) as '70-74',count(w.age_y) as '75-79',
count(x.age_y) as '80-84',count(y.age_y) as '85up',
count(e.main_pdx),
i.name as icdname
from vn_stat a
left outer join icd101 i on i.code=a.main_pdx
left outer join vn_stat b on b.vn=a.vn and b.sex="1"
left outer join vn_stat c on c.vn=a.vn and c.sex="2"
left outer join vn_stat g on g.vn=a.vn and g.age_y between '0' and '4'
left outer join vn_stat h on h.vn=a.vn and h.age_y between '5' and '9'
left outer join vn_stat j on j.vn=a.vn and j.age_y between '10' and '14'
left outer join vn_stat k on k.vn=a.vn and k.age_y between '15' and '19'
left outer join vn_stat l on l.vn=a.vn and l.age_y between '20' and '24'
left outer join vn_stat m on m.vn=a.vn and m.age_y between '25' and '29'
left outer join vn_stat n on n.vn=a.vn and n.age_y between '30' and '34'
left outer join vn_stat o on o.vn=a.vn and o.age_y between '35' and '39'
left outer join vn_stat p on p.vn=a.vn and p.age_y between '40' and '44'
left outer join vn_stat q on q.vn=a.vn and q.age_y between '45' and '49'
left outer join vn_stat r on r.vn=a.vn and r.age_y between '50' and '54'
left outer join vn_stat s on s.vn=a.vn and s.age_y between '55' and '59'
left outer join vn_stat t on t.vn=a.vn and t.age_y between '60' and '64'
left outer join vn_stat u on u.vn=a.vn and u.age_y between '65' and '69'
left outer join vn_stat v on v.vn=a.vn and v.age_y between '70' and '74'
left outer join vn_stat w on w.vn=a.vn and w.age_y between '75' and '79'
left outer join vn_stat x on x.vn=a.vn and x.age_y between '80' and '84'
left outer join vn_stat y on y.vn=a.vn and y.age_y between '85' and '129'
left outer join vn_stat d on d.vn=a.vn and d.pttype_in_region="Y"
left outer join vn_stat e on e.vn=a.vn and e.pttype_in_region="N"
where a.vstdate between '2011-06-01' and '2011-06-30'
and a.main_pdx<>'' and a.main_pdx is not null
group by a.main_pdx,i.name
order by a.main_pdx
ถ้าแก้ sql ตรงนี้ให้แสดงเป็น 10 อันดับโรคแรกของผู้ป่วยทันตกรรมต้องแก้ประมาณไหนครับ