BMS-HOSxP Community

HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: Tigger ที่ ธันวาคม 08, 2010, 09:25:01 AM

หัวข้อ: รบกวนดูคำสั่ง SQL ด้วยค่ะ
เริ่มหัวข้อโดย: Tigger ที่ ธันวาคม 08, 2010, 09:25:01 AM
ผู้ป่วยลงทะเบียนคลินิกพิเศษ 2 คลินิก (DM & HT) แล้วต้องการทราบว่าในวันที่มารับบริการ
เป็นผู้ป่วยเก่าหรือใหม่ โดยดูจากวันที่ลงทะเบียน โดยยึด DM เป็นหลัก แต่พอ run คำสั่งออกมา
จะได้วันที่ regdate ที่เป็น record แรก ซึ่งบางที่จะเป็นของ HT ต้องทำอย่างไรค่ะถึงจะได้วัน
regdate ของ DM

select count(distinct(v.hn)) from ovst v
           left outer join clinicmember cl on cl.hn=v.hn
           where (v.hn in (select c.hn from clinicmember c where clinic="001"))
           and v.hn in (select c.hn from clinicmember c where clinic="002")
           and  v.vstdate between "'+ds1+'" and "'+ds2+'"
           and v.main_dep="020"
           and cl.regdate >= "'+ds1+'"