ผมอยากแยก คำสั่ง จะเอาเฉพาะผู้ป่วยใน ตอนนี้ ออก LR รวมมาด้วย ผมต้องทำไง อ่ะครับ
select a.an,a.hn,a.regdate,concat(pt.pname,pt.fname,' ',pt.lname )as name,ic.icnp_classification_name,dch.name as dchtype,
et.name as er_type,a.age_y,s.name as department
,a.pdx,i1.name as pdxname,a.dx0,i2.name as namedx0,a.dx1,i3.name as namedx1,
a.dx2,i4.name as namedx2,
a.dx3,i5.name as namedx3,
a.dx4,i6.name as namedx4,
a.dx5,i7.name as namedx5,
a.dchdate,a.admdate,d.name as discharg_type,a.income
from an_stat a
left outer join patient pt on a.hn = pt.hn
left outer join spclty s on a.spclty = s.spclty
left outer join ipt i on a.an = i.an
left outer join dchstts d on i.dchstts = d.dchstts
left outer join icd101 i1 on a.pdx = i1.code
left outer join icd101 i2 on a.dx0 = i2.code
left outer join icd101 i3 on a.dx1 = i3.code
left outer join icd101 i4 on a.dx2 = i4.code
left outer join icd101 i5 on a.dx3 = i5.code
left outer join icd101 i6 on a.dx4 = i6.code
left outer join icd101 i7 on a.dx5 = i7.code
left outer join ipt_icnp ii on a.an = ii.an
left outer join icnp_classification ic on ii.icnp_classification_id = ic.icnp_classification_id
left outer join ipt ipt on a.an = ipt.an
left outer join dchtype dch on ipt.dchtype = dch.dchtype
left outer join er_regist er on a.vn = er.vn
left outer join er_emergency_type et on er.er_emergency_type =et.er_emergency_type
where a.regdate between '2011-10-01' and '2011-10-31'