BMS-HOSxP Community
HOSxP => HOSxP PCU => ข้อความที่เริ่มโดย: Admin banrai ที่ สิงหาคม 30, 2011, 21:02:40 PM
-
อยากทราบว่าจะเขียนคำสั่งอย่างไรให้นับจำนวนคนที่ป่วยด้วยโรคความดันโลหิตสูงและโรคเบาหวาน ซึ่งคน ๆ นั้นต้องป่วยทั้ง 2 โรค เช่นจากตาราง person_chronic person_id ที่ 58 ป่วยด้วยโรคความดันโลหิตสูงและโรคเบาหวาน ต้องเขียนคำสั่งอย่างไรให้นับ Person_id ที่ 58 ได้เท่ากับ 1 คน เท่านั้น
-
ถ้าเป็นแบบนี้พอได้มั้ยครับ
select count(distinct(cm.hn) )as cc
from clinicmember cm
left outer join vn_stat v on v.hn=cm.hn
where (cm.hn in (select hn from clinicmember where clinic="001"))
and (cm.hn in (select hn from clinicmember where clinic="002"))
and v.vstdate between "2011-01-01" and "2011-01-05"
-
ลองอันนี้ดูครับ
select person_id
from person_chronic
where clinic in ("001","002")
group by person_id
having count(person_id)=2
-
ลองอันนี้ดูครับ
select person_id
from person_chronic
where clinic in ("001","002")
group by person_id
having count(person_id)=2
ตามท่าน pop เลยครับ ลืมดูตาราง 555+
-
ขอบคุณครับ