ผมจา เลือกเอาคนไข้คลีนิกตรงสุขภาพมาใส่ตรงไหนอ่ะครับท่าน และเพิ่มคนไข้ที่เป็นเบาหวานด้วย อ่ะครับ ผม งง
select pt.cid,pt.hn, concat(pt.pname,pt.fname," ",pt.lname) as fullname,pt.birthday,concat(pt.addrpart," หมู่ ",pt.moopart," ต.",t3.name," อ.",t2.name," จ.",t1.name) as fulladdressname,
pt.moopart, ov.age_y ,os.bmi
from ovst ovst
left outer join patient pt on pt.hn=ovst.hn
left outer join vn_stat ov on ov.vn=ovst.vn
left outer join opdscreen os on os.vn=ovst.vn
left outer join thaiaddress t1 on t1.chwpart=pt.chwpart
and t1.amppart="00" and t1.tmbpart="00"
left outer join thaiaddress t2 on t2.chwpart=pt.chwpart
and t2.amppart=pt.amppart and t2.tmbpart="00"
left outer join thaiaddress t3 on t3.chwpart=pt.chwpart
and t3.amppart=pt.amppart and t3.tmbpart=pt.tmbpart
where ov.vstdate between "2009-07-01" and "2009-07-31"
and ov.aid="960501"
and ov.moopart in ('1','2','3','4','5','6','7','8','9','10','11','12','13')
and ( (ov.pdx >= "i10" and ov.pdx <= "i159")
or (ov.dx0 >= "i10" and ov.dx0 <= "i159")
or (ov.dx1 >= "i10" and ov.dx1 <= "i159")
or (ov.dx2 >= "i10" and ov.dx2 <= "i159")
or (ov.dx3 >= "i10" and ov.dx3 <= "i159")
or (ov.dx4 >= "i10" and ov.dx4 <= "i159")
or (ov.dx5 >= "i10" and ov.dx5 <= "i159") )
group by ov.hn
order by pt.moopart,pt.hn