ผมทำไว้ นำเข้าทดสอบดูนะครับ แต่ต้องไปแก้ lab_items_code ให้ตรงกับของตนเองนะครับ
select patient.hn,patient.addrpart,patient.moopart, ovstdiag.icd10,ovst.vstdate,
vn_stat.age_y as pt_age,vn_stat.sex as pt_sex,opdscreen.cc,
concat(patient.pname,patient.fname,' ',patient.lname) as patientname,opdscreen.bw,lab_order.lab_order_result,
t1.name as tumbolname,t2.name as ampurname, t3.name as changwatname,
icd101.name as DiagName,if(vn_stat.sex ="1",(((140-vn_stat.age_y)*opdscreen.bw)/(72*lab_order.lab_order_result)),
(((140-vn_stat.age_y)*opdscreen.bw)/(72*lab_order.lab_order_result))*.85) as ccr
from ovst
left outer join vn_stat on vn_stat.vn=ovst.vn
left outer join opdscreen on opdscreen.vn = ovst.vn
left outer join opitemrece on opitemrece.vn = ovst.vn
left outer join patient on patient.hn = ovst.hn
left outer join lab_head on lab_head.vn=ovst.vn
join lab_order on lab_order.lab_order_number = lab_head.lab_order_number and lab_items_code = '78'
left outer join thaiaddress t1 on t1.codetype='3' and t1.chwpart=patient.chwpart
and t1.amppart=patient.amppart and t1.tmbpart=patient.tmbpart
left outer join thaiaddress t2 on t2.codetype='2' and t2.chwpart=patient.chwpart
and t2.amppart=patient.amppart
left outer join thaiaddress t3 on t3.codetype='1' and t3.chwpart=patient.chwpart
join ovstdiag on ovstdiag.hn=ovst.hn and ovstdiag.vstdate=ovst.vstdate
and ovstdiag.vsttime=ovst.vsttime
and(ovstdiag.icd10 like'e10%' or ovstdiag.icd10 like'e11%' or ovstdiag.icd10 like'e12%'
or ovstdiag.icd10 like'e13%' or ovstdiag.icd10 like'e14%')
left outer join icd101 on icd101.code = ovstdiag.icd10
where ovst.vstdate BETWEEN '2006-04-24' and '2006-05-01'
group by patient.hn,ovst.vstdate,ovst.vsttime, patient.tmbpart,patient.moopart,patient.addrpart,patientname