BMS-HOSxP Community

HOSxP => HOSxP PCU => ข้อความที่เริ่มโดย: Admin banrai ที่ สิงหาคม 30, 2011, 21:02:40 PM

หัวข้อ: สอบถาม SQL หน่อยครับ
เริ่มหัวข้อโดย: Admin banrai ที่ สิงหาคม 30, 2011, 21:02:40 PM
อยากทราบว่าจะเขียนคำสั่งอย่างไรให้นับจำนวนคนที่ป่วยด้วยโรคความดันโลหิตสูงและโรคเบาหวาน ซึ่งคน ๆ นั้นต้องป่วยทั้ง 2 โรค เช่นจากตาราง person_chronic   person_id ที่ 58 ป่วยด้วยโรคความดันโลหิตสูงและโรคเบาหวาน ต้องเขียนคำสั่งอย่างไรให้นับ Person_id ที่ 58 ได้เท่ากับ 1 คน เท่านั้น
หัวข้อ: Re: สอบถาม SQL หน่อยครับ
เริ่มหัวข้อโดย: niyomstd ที่ สิงหาคม 30, 2011, 22:16:42 PM
ถ้าเป็นแบบนี้พอได้มั้ยครับ
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"
หัวข้อ: Re: สอบถาม SQL หน่อยครับ
เริ่มหัวข้อโดย: pop_hosxp ที่ สิงหาคม 31, 2011, 07:11:17 AM
ลองอันนี้ดูครับ

select person_id
from person_chronic
where clinic in ("001","002")
group by person_id
having count(person_id)=2
หัวข้อ: Re: สอบถาม SQL หน่อยครับ
เริ่มหัวข้อโดย: niyomstd ที่ สิงหาคม 31, 2011, 08:06:40 AM
ลองอันนี้ดูครับ

select person_id
from person_chronic
where clinic in ("001","002")
group by person_id
having count(person_id)=2
ตามท่าน pop เลยครับ ลืมดูตาราง 555+
หัวข้อ: Re: สอบถาม SQL หน่อยครับ
เริ่มหัวข้อโดย: Admin banrai ที่ สิงหาคม 31, 2011, 16:29:11 PM
ขอบคุณครับ