select r.vn,i.an,i.hn,p.pname,p.fname,p.lname,i.regdate,i.dchdate,i.dchtype,i.rw
,a.pdx,a.dx0,a.dx1,a.dx2,a.dx3,a.dx4,a.dx5
,a.op0,a.op1,a.op2,a.op3,a.op4,a.op5
,r.hospcode
from referout r
left join ipt i on r.vn=i.an
left join an_stat a on i.an=a.an
left join patient p on i.hn=p.hn
where refer_date between '2010-10-1' and '2011-9-30'
and r.department in ('IPD','LR','WARD')
and i.rw>=0 and i.rw<0.5
ประมาณนี้มั๊ย
กรุณาตรวจสอบ dchtype,rw=0,pdx