select a.an,a.hn,concat(pt.pname,pt.fname,' ',pt.lname )as name,s.name as sex,a.pdx,i.name as codename,a.dx0,i0.name as dx0name,
a.dx1,i1.name as dx1name,a.dx2,i2.name as dx2name,a.dx3,i3.name as dx3name,a.dx4,i4.name as dx4name,a.dx5,i5.name as dx5name,
a.admdate_cut24,a.income ,a.pttype ,p.name as ptname,ip.dchtype,d.name as dchtype
from an_stat a
left outer join patient pt on a.hn = pt.hn
left outer join icd101 i on a.pdx = i.code
left outer join icd101 i0 on a.dx0 = i0.code
left outer join icd101 i1 on a.dx1 = i1.code
left outer join icd101 i2 on a.dx2 = i2.code
left outer join icd101 i3 on a.dx3 = i3.code
left outer join icd101 i4 on a.dx4 = i4.code
left outer join icd101 i5 on a.dx5 = i5.code
left outer join pttype p on a.pttype = p.pttype
left outer join ipt ip on a.an = ip.an
left outer join dchtype d on d.dchtype = ip.dchtype
left outer join sex s on a.sex = s.code
where a.regdate between '2010-10-01' and '2010-10-31'
ลองดูครับช้าหน่อย