ประมาณนี้เปล่าครับ.....
select a.hn,a.an,a.regdate,a.dchdate,a.lastvisit,a.pdx,
a.age_y,age_m,age_d,i.name as pdxname,a.aid,w.name,w.ward,
concat(p.pname,"",p.fname," ",p.lname) as ptname
from an_stat a
left outer join patient p on p.hn=a.hn
left outer join icd101 i on i.code=substring(a.pdx,1,3)
left outer join ward w on w.ward=a.ward ' +
where a.dchdate between '2008-03-01' and '2008-03-15' and '
a.lastvisit <= 28