BMS-HOSxP Community
HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: nan_it ที่ มิถุนายน 10, 2009, 11:52:57 AM
-
อ.ท่านใดพอจะมีรายงานผู้ป่วยเบาหวานที่รับยา aspirin มั้ยครับ (ขอกันตรงๆ) ผมลองหัดเขียนคำสั่งเอง ได้แค่นี้ครับ
select distinct(op.hn), concat(pt.pname,pt.fname,' ',pt.lname) as name
from vn_stat ov
left outer join opitemrece op on op.vn = ov.vn
left outer join clinicmember cl on cl.hn = ov.hn
left outer join patient pt on pt.hn = ov.hn
where op.icode in ('1480022','1000038','1520016')
and cl.clinic = '002'
ผมใช้คำสั่ง distinct ถูกมั้ยครับ แต่พอผม select ov.age_y เพิ่ม ข้อมูล hn ก็ซ้ำเหมือนเดิมครับ
-
select distinct(op.hn), concat(pt.pname,pt.fname,' ',pt.lname),ov.age_y
from vn_stat ov
left outer join opitemrece op on op.vn = ov.vn
left outer join clinicmember cl on cl.hn = ov.hn
left outer join patient pt on pt.hn = ov.hn
where op.icode in ('1480022','1000038','1520016')
and cl.clinic = '002'
group by ov.hn
order by ov.hn desc
สาเหตุเกิดจาก ฟิวส์ age_y ในแต่จะ Hn มีหลายค่าครับเพราะอายุคนเราจะเพิ่มไปเลื่อนๆ ในตาราง Vn_stat จะเอาอายุในช่วงที่เป็นโรคนั้นๆๆครับ
-
ขอบคุณค้าบ