BMS-HOSxP Community

HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: Bluebird ที่ กรกฎาคม 30, 2009, 08:11:17 AM

หัวข้อ: คำสั่ง ประชากรในเขตพื้นที่ ที่เป็นเบาหวาน
เริ่มหัวข้อโดย: Bluebird ที่ กรกฎาคม 30, 2009, 08:11:17 AM
select pt.*,ov.*
from vn_stat ov ,patient pt ,ovst ovst
where  ov.vn=ovst.vn and pt.hn=ov.hn and ov.vstdate between "2007-01-01" and  "2009-07-30" and ov.hn=pt.hn
 and ov.aid="960501"
 and ov.age_y>= 0
 and ov.age_y<= 200
 and ( (ov.pdx >= "E10" and ov.pdx <= "E148")
 or (ov.dx0 >= "E10" and ov.dx0 <= "E148")
 or (ov.dx1 >= "E10" and ov.dx1 <= "E148")
 or (ov.dx2 >= "E10" and ov.dx2 <= "E148")
 or (ov.dx3 >= "E10" and ov.dx3 <= "E148")
 or (ov.dx4 >= "E10" and ov.dx4 <= "E148")
 or (ov.dx5 >= "E10" and ov.dx5 <= "E148") )

หากไม่ต้องการให้ HN ซ้ำแก้ไขตรงไหนครับ
หัวข้อ: Re: คำสั่ง ประชากรในเขตพื้นที่ ที่เป็นเบาหวาน
เริ่มหัวข้อโดย: Neo ที่ กรกฎาคม 30, 2009, 08:19:23 AM
เพิ่ม group by ov.hn ต่อท้ายครับครับ ตามนี้ครับ

select pt.*,ov.*
from vn_stat ov ,patient pt ,ovst ovst
where  ov.vn=ovst.vn and pt.hn=ov.hn and ov.vstdate between "2007-01-01" and  "2009-07-30" and ov.hn=pt.hn
 and ov.aid="960501"
 and ov.age_y>= 0
 and ov.age_y<= 200
 and ( (ov.pdx >= "E10" and ov.pdx <= "E148")
 or (ov.dx0 >= "E10" and ov.dx0 <= "E148")
 or (ov.dx1 >= "E10" and ov.dx1 <= "E148")
 or (ov.dx2 >= "E10" and ov.dx2 <= "E148")
 or (ov.dx3 >= "E10" and ov.dx3 <= "E148")
 or (ov.dx4 >= "E10" and ov.dx4 <= "E148")
 or (ov.dx5 >= "E10" and ov.dx5 <= "E148") )
group by ov.hn