BMS-HOSxP Community

HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: Guitar-hero ที่ มกราคม 11, 2011, 20:12:17 PM

หัวข้อ: ขอ sql ดึงข้อมูล เด็ก อายุ 0-5 ปี หน่อยครับ (ทางฝั่ง PCU)
เริ่มหัวข้อโดย: Guitar-hero ที่ มกราคม 11, 2011, 20:12:17 PM
คือต้องการดึง ข้อมูลเด็ก 0-5 ปี ไปทำรายงานของ PCU ครับ ไม่ทราบว่าต้องใช้ คำสั่ง sql อย่างไรครับ
หัวข้อ: Re: ขอ sql ดึงข้อมูล เด็ก อายุ 0-5 ปี หน่อยครับ (ทางฝั่ง PCU)
เริ่มหัวข้อโดย: Farbrinet ที่ มกราคม 14, 2011, 10:43:02 AM
ไปที่บัญชี 1 ครับ แล้วไปที่แท็บค้นหากลุ่มเป้าหมาย ฝั่งขวามือ แล้วไปเปิด เมนู Tools ไปเลือกที่ SQL Trace แล้วให้ไปใส่ช่วงอายุ 0 - 5 ปี แล้วกลับไปดูที่ Sql Trace จะมีคำสั่ง Sql เกิดขึ้นลองหาดูครับว่าน่าจะไปบรรทัดใด
หัวข้อ: Re: ขอ sql ดึงข้อมูล เด็ก อายุ 0-5 ปี หน่อยครับ (ทางฝั่ง PCU)
เริ่มหัวข้อโดย: MR.KRAPONG<> ที่ มกราคม 14, 2011, 11:24:49 AM
select concat(p.pname,p.fname,"   ",p.lname) as nd
, p.birthday
, (to_days(curdate())-to_days(birthday))/365 as ye
, datediff(curdate(),p.birthday) as dd
, year(curdate())-year(p.birthday) as dm
, month(curdate())-month(p.birthday) as dm
, s.name as sexname
,p.addrpart as "บ้านเลขที่"
,p.moopart as "หมู่"
,t1.name as "ตำบล"
,t2.name as  "อำเภอ"
,t3.name as "จังหวัด"
,concat("บ้านเลขที่",p.addrpart," ม. ",p.moopart,"  ต. ",t1.name,"  อ. ",t2.name,"  จ. ",t3.name) as fulladdr
from patient  p
left outer join thaiaddress t1 on t1.tmbpart=p.tmbpart
and t1.amppart=p.amppart and t1.chwpart=p.chwpart  and t1.codetype = 3
left outer join thaiaddress t2 on  t2.amppart=p.amppart and t2.chwpart=p.chwpart  and t2.codetype = 2
left outer join thaiaddress t3 on  t3.chwpart=p.chwpart  and t3.codetype = 1
left outer join sex s on s.code=p.sex
where  year(curdate())-year(p.birthday)<=5  and month(curdate())-month(p.birthday)<=0
and p.chwpart=50   and p.amppart ="03" and p.tmbpart="01"


ผมเคยใช้ตัวนี้ครับ   ไม่รู้ใช่หรือป่าวครับ
หัวข้อ: Re: ขอ sql ดึงข้อมูล เด็ก อายุ 0-5 ปี หน่อยครับ (ทางฝั่ง PCU)
เริ่มหัวข้อโดย: taw2010 ที่ มกราคม 15, 2011, 16:30:20 PM
ไปที่รายงาน ----->   ค้นหาจำนวนผู้ป่วยนอก ค่ะแล้วก็ใส่เงื่อนไขที่ต้องการ ค่ะก็จะได้แล้วค่ะ
ไม่รู้ว่าตกตามที่ต้องการหรือเปล่านะค่ะ
หัวข้อ: Re: ขอ sql ดึงข้อมูล เด็ก อายุ 0-5 ปี หน่อยครับ (ทางฝั่ง PCU)
เริ่มหัวข้อโดย: saan ที่ มกราคม 16, 2011, 09:42:23 AM
 ;D  ผมใช้ตัวนี้ครับ

select p.cid ,concat(p.pname,p.fname," ",p.lname) as pt ,p.birthdate,h.address ,v.village_moo as mu ,
p.father_name as papa ,p.mother_name as mama from person_epi pe
left outer join person p on p.person_id=pe.person_id
left outer join house h on h.house_id=p.house_id
left outer join village v on v.village_id = h.village_id
where (pe.discharge<>"Y"  or pe.discharge is null)
and p.house_regist_type_id in ("1","3")
and p.age_y < 6 and p.death not in ("Y")
order by     mu
หัวข้อ: Re: ขอ sql ดึงข้อมูล เด็ก อายุ 0-5 ปี หน่อยครับ (ทางฝั่ง PCU)
เริ่มหัวข้อโดย: saan ที่ มกราคม 16, 2011, 09:47:44 AM
 ;D  ตัวนี้อีก เลือกเอา น่ะครับ แล้วแต่ จะ Apply

select h.village_id,h.address,p.* ,pc.name as pttype_name,x.name as sex_name  ,n.name as nationality_name,
 concat(p2.fname,' ',p2.lname) as father_name ,  concat(p3.fname,' ',p3.lname) as mother_name ,
  concat(p4.fname,' ',p4.lname) as couple_name ,  e.name as education_name ,
  o.name as occupation_name,r.name as religion_name ,  y.name as marrystatus_name ,t.house_regist_type_name ,
  f.family_no  , pp.person_house_position_name  from person  p
  left outer join house h on h.house_id = p.house_id
  left outer join pttype pc on pc.pttype = p.pttype
  left outer join sex x on x.code = p.sex
  left outer join nationality n on n.nationality = p.nationality
  left outer join education e on e.education = p.education
  left outer join occupation o on o.occupation = p.occupation
  left outer join religion r on r.religion = p.religion
  left outer join marrystatus y on y.code = p.marrystatus
  left outer join person p2 on p2.person_id = p.father_person_id
  left outer join person p3 on p3.person_id = p.mother_person_id
  left outer join person p4 on p4.person_id = p.couple_person_id
  left outer join person_house_position pp on pp.person_house_position_id = p.person_house_position_id
  left outer join family f on f.family_id = p.family_id
  left outer join house_regist_type t on t.house_regist_type_id = p.house_regist_type_id
  where p.death = 'N'   and p.age_y between 0 and 6      and h.house_id <> 1
  order by round(h.address),p.person_id       desc