BMS-HOSxP Community

HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: namlao ที่ กุมภาพันธ์ 03, 2016, 16:44:00 PM

หัวข้อ: join ตาราง clinicmember
เริ่มหัวข้อโดย: namlao ที่ กุมภาพันธ์ 03, 2016, 16:44:00 PM
ต้องการ join ตาราง clinicmember ในคิวรี่นี้ด้วยนะครับ ไม่รู้ว่าจะเพิ่มอย่างไร อ.ช่วยด้วยครับ
หัวข้อ: Re: join ตาราง clinicmember
เริ่มหัวข้อโดย: golf_win ที่ กุมภาพันธ์ 03, 2016, 17:25:01 PM
SELECT lh.vn,lh.hn,p.pname,p.fname,p.lname,v.sex,
v.age_y,p.addrpart,p.moopart,t.full_name,v.pdx,
i.`name`,lh.order_date,lo.lab_order_result,o.egfr,
pe.`name`,if(o.egfr>=90,'1',if(o.egfr between 60 and 89.999,'2',if(o.egfr between 45 and 59.999,'3a',if(o.egfr between 30 and 44.999,'3b',if(o.egfr between 15 and 29.999,'4',if(o.egfr<15,'5','')))))) AS state,
GROUP_CONCAT(distinct(l.name) SEPARATOR ',') as clinic
FROM lab_order AS lo
LEFT OUTER JOIN lab_head AS lh ON lo.lab_order_number = lh.lab_order_number
LEFT OUTER JOIN vn_stat AS v ON v.vn = lh.vn
LEFT OUTER JOIN opdscreen AS o ON v.vn = o.vn
LEFT OUTER JOIN patient AS p ON p.hn = lh.hn
LEFT OUTER JOIN icd101 AS i ON i.`code` = v.pdx
LEFT OUTER JOIN thaiaddress AS t ON t.addressid = concat(p.chwpart,p.amppart,p.tmbpart)
LEFT OUTER JOIN pttype AS pe ON pe.pttype = v.pttype
LEFT OUTER JOIN clinicmember c on c.hn=v.hn
LEFT OUTER JOIN clinic l on l.clinic=c.clinic
where v.vn is not null and lo.lab_items_code in ('155') and (lh.report_date between '2015-12-01' and '2015-12-10')
group by v.vn