BMS-HOSxP Community

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

หัวข้อ: ขอความช่วยเหลือ เรื่อง sql แสดง อำเภอ จังหวัด ด้วยครับ
เริ่มหัวข้อโดย: Guitar-hero ที่ กรกฎาคม 08, 2011, 15:54:09 PM
คือจะทำรายงานประมาณนี้ครับ

---------------------------------------------------------------------------------
hn             ชื่อ-สกุล             ตำบล               อำเภอ               จังหวัด
---------------------------------------------------------------------------------
xx            xxxxxxxx          xxxxx               xxxx              xxxxxx
xx            xxxxxxxx          xxxxx               xxxx              xxxxxx

ไม่ทราบว่าต้องเขียน sql ยังไงบ้างครับ
หัวข้อ: Re: ขอความช่วยเหลือ เรื่อง sql แสดง อำเภอ จังหวัด ด้วยครับ
เริ่มหัวข้อโดย: lo_singburihosp ที่ กรกฎาคม 08, 2011, 16:23:40 PM
select concat(p.pname,p.fname,' ',p.lname) as tname,p.hn,concat(p.addrpart,' Á.',p.moopart,' µ.',t1.name,' Í.',t2.name,' ¨.',t3.name) as tt
from patient p
left outer join thaiaddress t1 on t1.codetype='3' and t1.chwpart=p.chwpart
and t1.amppart=p.amppart and t1.tmbpart=p.tmbpart
left outer join thaiaddress t2 on t2.codetype='2' and t2.chwpart=p.chwpart
and t2.amppart=p.amppart
left outer join thaiaddress t3 on t3.codetype='1' and t3.chwpart=p.chwpart

limit 1000
หัวข้อ: Re: ขอความช่วยเหลือ เรื่อง sql แสดง อำเภอ จังหวัด ด้วยครับ
เริ่มหัวข้อโดย: nahos ที่ กรกฎาคม 08, 2011, 16:25:16 PM
    SELECT p.hn,concat(p.pname,p.fname,'  ',p.lname) as ptname ,t1.name as chw_name, t2.name as amp_name,t3.name as tmb_name
         FROM patient p
         LEFT OUTER JOIN thaiaddress t1 on t1.chwpart=p.chwpart  and t1.codetype='1'
         LEFT OUTER JOIN thaiaddress t2 on t2.chwpart=p.chwpart  and t2.amppart=p.amppart and t2.codetype='2'
         LEFT OUTER JOIN thaiaddress t3 on t3.chwpart=p.chwpart  and t3.amppart=p.amppart
         and t3.tmbpart=  p.tmbpart and t3.codetype='3'
        limit 10

ไม่ทัน  ;D ;D ;D
หัวข้อ: Re: ขอความช่วยเหลือ เรื่อง sql แสดง อำเภอ จังหวัด ด้วยครับ
เริ่มหัวข้อโดย: Guitar-hero ที่ กรกฎาคม 08, 2011, 16:29:41 PM
ขอบคุณมากครับ