BMS-HOSxP Community

HOSxP => MySQL => ข้อความที่เริ่มโดย: s.pookhao ที่ สิงหาคม 04, 2016, 10:18:20 AM

หัวข้อ: อยากได้คำสั่งตรวจสอบการฉีดยาแต่ไม่ลงยาที่ฉีด
เริ่มหัวข้อโดย: s.pookhao ที่ สิงหาคม 04, 2016, 10:18:20 AM
อยากได้ sql ตรวจสอบคนที่มีการทำหัตถการฉีดยาDT / ฉีดยา PCEC แต่ไม่ลง Vaccine
หัวข้อ: Re: อยากได้คำสั่งตรวจสอบการฉีดยาแต่ไม่ลงยาที่ฉีด
เริ่มหัวข้อโดย: เกื้อกูล ครับ.. ที่ สิงหาคม 04, 2016, 14:34:44 PM
อยากได้ sql ตรวจสอบคนที่มีการทำหัตถการฉีดยาDT / ฉีดยา PCEC แต่ไม่ลง Vaccine

ลองดูนะ
select er.vn,er.vstdate,v.vsttime,v.hn,concat(p.pname,p.fname,space(1),p.lname) as ptname,i.name as vaccine_order
,if(ovc.person_vaccine_id is null,'No','Yes') as yn,pv.vaccine_name,sc.cc
,if(ovc.person_vaccine_id is null,0,1) as yy
,if(ovc.person_vaccine_id is null,1,0) as nn,d2.name as doctor_name
from er_regist er
inner join ovst v on v.vn = er.vn
left join patient p on p.hn = v.hn
left join ovst_vaccine ovc on ovc.vn = er.vn
left join opitemrece op on op.vn = er.vn
left join drugitems i on i.icode = op.icode
left join opdscreen sc on sc.vn = er.vn
left join person_vaccine pv on pv.person_vaccine_id = ovc.person_vaccine_id
left join doctor d on d.code = er.er_doctor
inner join er_regist_oper eo on eo.vn=er.vn and eo.er_oper_code in(----------รหัสกิจกรรมหัตการห้องฉุกเฉินที่ชี้บ่งว่าคือฉีดวัคซิน A B C D)
left outer join doctor d2 on d2.code=eo.doctor
where er.vstdate between "2016-05-18" and "2016-07-31"
and i.drugcategory like กลุ่มวัคซิน'
and (pv.vaccine_name is null or pv.vaccine_name="")
group by er.vn,op.icode
order by er.vstdate,er.vn

ประมาณนี้ แนว ๆ นี้ครับ  ลองไปปรับใช้ดูนะ