นำ Code ที่ อาจารย์ให้มาทดลองแล้ว ค่าออกมาไม่ตรงครับ OPD มีค่าห้องและค่าอาหารออกมาด้วย ผมเลยสงสัยว่าใช้ตารางไหนครับ ระหว่าง income กับ income_group ที่ใช้นำมาเทียบกับตาราง vn_stat ช่วยดูให้ทีครับ
ขอบคุณครับ
Script ดึง IPD Data
SELECT "10874" as hcode,a.an,p.hn,a.vn,p.pname,p.fname,p.lname,p.birthday,p.sex,a.regdate,a.dchdate,w.name as wardname,s.name as pttypename,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,a.op6,a.inc16 as inc01,a.inc08 as inc02 ,iis.uinc_drug as inc03,0 as inc04,iis.uinc_nondrug as inc05,a.inc02 as inc06,a.inc01 as inc07,a.inc04 as inc08,a.inc05 as inc09,a.inc09 as inc10,a.inc06 as inc11,a.inc14 as inc12,a.inc11 as inc13,a.inc13 as inc14,0 as inc15,a.inc17 as inc16,0 as inc17,iis.uinc_drug as incDrug,a.los,a.drg,a.rw,i.adjrw from an_stat a
left JOIN patient p on p.hn=a.hn
left join inc_ipd_stat iis on iis.an=a.an
left JOIN ward w on w.ward=a.ward
LEFT JOIN pttype pty on pty.pttype=a.pttype
left JOIN pcode s on s.code=pty.pcode
LEFT JOIN ipt i ON i.an=a.an
WHERE a.dchdate BETWEEN '2011-10-01' and '2012-03-31'
Script ดึง OPD Data
SELECT "10874" as hcode,a.vn,a.vstdate,p.hn,a.cid,p.pname,p.fname,p.lname,p.birthday,p.sex,s.name as pttypename,"OPD" as WardName,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,a.inc16 as inc01,a.inc08 as inc02 ,inc_drug as inc03,0 as inc04,inc_nondrug as inc05,a.inc02 as inc06,a.inc01 as inc07,a.inc04 as inc08,a.inc05 as inc09,a.inc09 as inc10,a.inc06 as inc11,a.inc14 as inc12,a.inc11 as inc13,a.inc13 as inc14,0 as inc15,a.inc17 as inc16,0 as inc17,a.inc_drug as incdrug
from vn_stat a
left JOIN patient p on p.hn=a.hn
LEFT JOIN pttype pty on pty.pttype=a.pttype
left JOIN pcode s on s.code=pty.pcode
WHERE a.vstdate BETWEEN '2011-10-01' and '2012-03-31'
----------------------------------------------------------------------------