BMS-HOSxP Community

HOSxP => HOSxP PCU => ข้อความที่เริ่มโดย: numkum ที่ เมษายน 21, 2010, 23:36:08 PM

หัวข้อ: อยากรู้รายชื่อในตาราง person_chronic
เริ่มหัวข้อโดย: numkum ที่ เมษายน 21, 2010, 23:36:08 PM
 :)ถ้าผมอยากรู้ว่าในตาราง person_chronic นั้นมีผู้ป่วย ชื่อ,นามสกุล,อายุ,บ้านเลขที่,หมู่,ตำบล,อำเภอ,จังหวัด ผมต้องใช้คำสั่ง SQL ว่าอย่างไรครับ :)
หัวข้อ: Re: อยากรู้รายชื่อในตาราง person_chronic
เริ่มหัวข้อโดย: nuttavut ที่ เมษายน 22, 2010, 00:07:25 AM
:)ถ้าผมอยากรู้ว่าในตาราง person_chronic นั้นมีผู้ป่วย ชื่อ,นามสกุล,อายุ,บ้านเลขที่,หมู่,ตำบล,อำเภอ,จังหวัด ผมต้องใช้คำสั่ง SQL ว่าอย่างไรครับ :)

แบบนี้ไหมครับ  ;D ;D ;D

โค๊ด: [Select]
select c.clinic,cl.name as clinic_name,h.village_id,h.address,concat(p.pname,p.fname," ",p.lname)as ptname,
       p.cid ,timestampdiff(year,p.birthdate,now()) as age_y,pc.name as pttype_name,x.name as sex_name  ,
 n.name as nationality_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 ,c.*,
 concat(h.address," Á.",vl.village_moo," ",th.full_name) as address_name
 from  person_chronic  c
 left outer join person  p on c.person_id =p.person_id
 left outer join house h on h.house_id = p.house_id
 left outer join village vl on h.village_id = vl.village_id
 left outer join thaiaddress th on  th.addressid = vl.address_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_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
 left outer join clinic cl on cl.clinic=c.clinic
 where c.clinic='002'
หัวข้อ: Re: อยากรู้รายชื่อในตาราง person_chronic
เริ่มหัวข้อโดย: numkum ที่ เมษายน 22, 2010, 00:34:18 AM
 ;Dขอบคุณมากครับ อ.nuttavut :-*