ลองรัยดูแล้ว
ปรากฎว่า คนไข้ที่เป็นทั้ง HT และ DM มีแล้ว เมื่อกรอง HT อย่างเดียว หรือ DM อย่างเดียวจะเข้ามาด้วย
select vn.vn,pt.cid,pt.hn,concat(pt.pname,pt.fname," ",pt.lname) as fullname,vn.age_y,count(c.clinic) as cc,dc.screen_datetime
from depression_screen dc
left outer join vn_stat vn on vn.vn=dc.vn
left outer join clinicmember c on c.hn=vn.hn
left outer join patient pt on pt.hn=c.hn
where dc.screen_datetime between "2011-01-01" and "2011-01-31"
and (c.clinic in (select sys_value from sys_var where sys_name = "ht_clinic_code")
or c.clinic in (select sys_value from sys_var where sys_name = "dm_clinic_code") )
group by c.hn ,pt.pname,pt.fname,pt.lname
having count(c.clinic)>1
เมื่อ HT อย่างเดียว
select vn.vn,pt.cid,pt.hn,concat(pt.pname,pt.fname," ",pt.lname) as fullname,vn.age_y,count(c.clinic) as cc,dc.screen_datetime
from depression_screen dc
left outer join vn_stat vn on vn.vn=dc.vn
left outer join clinicmember c on c.hn=vn.hn
left outer join patient pt on pt.hn=c.hn
where dc.screen_datetime between "2011-01-01" and "2011-01-31"
and c.clinic in (select sys_value from sys_var where sys_name = "ht_clinic_code")
group by c.hn ,pt.pname,pt.fname,pt.lname
having count(c.clinic)=1
เมื่อ DM อย่างเดียว
select vn.vn,pt.cid,pt.hn,concat(pt.pname,pt.fname," ",pt.lname) as fullname,vn.age_y,count(c.clinic) as cc,dc.screen_datetime
from depression_screen dc
left outer join vn_stat vn on vn.vn=dc.vn
left outer join clinicmember c on c.hn=vn.hn
left outer join patient pt on pt.hn=c.hn
where dc.screen_datetime between "2011-01-01" and "2011-01-31"
and c.clinic in (select sys_value from sys_var where sys_name = "dm_clinic_code")
group by c.hn ,pt.pname,pt.fname,pt.lname
having count(c.clinic)=1