BMS-HOSxP Community

HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: treera ที่ สิงหาคม 28, 2009, 11:11:54 AM

หัวข้อ: อยากได้ sql ในการดึงรายงาน 504 และ 505
เริ่มหัวข้อโดย: treera ที่ สิงหาคม 28, 2009, 11:11:54 AM
สวัสดีครับอาจารย์
ผมอยากได้ sql ในการดึงรายงาน 504 และ 505
เพื่อดึงข้อมูลเข้ามารวมใน database อีกตัวหนึ่งครับ
โดยดึงข้อมูลในส่วนของรหัสสถานพยาบาลแนบมาด้วย
ในทุกแถวของข้อมูลครับ
หัวข้อ: Re: อยากได้ sql ในการดึงรายงาน 504 และ 505
เริ่มหัวข้อโดย: woravet ที่ สิงหาคม 28, 2009, 12:19:08 PM
รง.504
select a.*,ifnull(d.amount,0) as amount
from rpt_504_name a
left join (select b.id,count(b.id) as amount from rpt_504_code b,ovstdiag c
where c.icd10 between b.code1 and b.code2
and c.vstdate between '2009-1-1' and '2009-1-31'
group by b.id) d on d.id=a.id
order by a.id

รง.505
select a.*,ifnull(d.amount,0) as amount
from rpt_505_name a
left join (select x.id,count(x.id) as amount from rpt_505_code x,ipt y,iptdiag z    where z.icd10 between x.code1 and x.code2
and y.an=z.an and y.dchdate between '2009-1-1' and '2009-1-31'
group by x.id) d on d.id=a.id
order by a.id
หัวข้อ: Re: อยากได้ sql ในการดึงรายงาน 504 และ 505
เริ่มหัวข้อโดย: treera ที่ สิงหาคม 28, 2009, 14:21:00 PM
ขอบคุณมากครับ