BMS-HOSxP Community

HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: prapansak ที่ เมษายน 22, 2013, 11:30:02 AM

หัวข้อ: ช่วยดู Code รายงานทันตให้หน่อยจ้า
เริ่มหัวข้อโดย: prapansak ที่ เมษายน 22, 2013, 11:30:02 AM
มีปัญหาว่าติดตรงที่ต้องการแยกอายุด้วย เช่น 0-4 ปี 3-5 ปี แต่ผมหาวิธีแยกอายุไม่ได้ครับ
หัวข้อ: Re: ช่วยดู Code รายงานทันตให้หน่อยจ้า
เริ่มหัวข้อโดย: prapansak ที่ เมษายน 22, 2013, 11:48:56 AM
select v.hospsub,h.name ,count(distinct(d.hn)),count(d.hn),sum(v.age_y between '0' and '4' )  as "þ.¤¹"
from dtmain d
left outer join vn_stat v on v.vn = d.vn
left outer join hospcode h on h.hospcode=v.hospsub
where d.vstdate between '2013-01-01' and '2013-01-31' and v.hospmain=10874 and hospsub<>""
group by v.hospsub

ได้แล้วแบบ งง
ผมลองเปลี่ยน จาก count เป็น sum ได้เฉยเลย งง โค๊ดผมถูกไหมครับ ดูให้ที
select v.hospsub,h.name ,count(distinct(d.hn)),count(d.hn),sum(v.age_y between '0' and '4' )  as "&Atilde;&frac34;.&curren;&sup1;"
from dtmain d
left outer join vn_stat v on v.vn = d.vn
left outer join hospcode h on h.hospcode=v.hospsub
where d.vstdate between '2013-01-01' and '2013-01-31' and v.hospmain=10874 and hospsub<>""
group by v.hospsub
หัวข้อ: Re: ช่วยดู Code รายงานทันตให้หน่อยจ้า
เริ่มหัวข้อโดย: samcom2 ที่ เมษายน 23, 2013, 14:06:12 PM
select v.hospsub,h.name ,count(distinct(d.hn)) as kon,count(distinct(d.vn)) as krung, count(d.hn) as ngan,
 count(distinct(case when v.age_y <= 2 then d.vn  end) ) as age_0_2,
 count(distinct(case when v.age_y >= 3 and v.age_y <= 5 then d.vn  end) ) as age_3_5,
 count(distinct(case when v.age_y >= 6 and v.age_y <= 14 then d.vn  end) ) as age6_14,
 count(distinct(case when v.age_y >= 15 and v.age_y <= 40 then d.vn  end) ) as age15_40,
 count(distinct(case when v.age_y >= 41 and v.age_y <= 59 then d.vn  end) ) as age41_59,
 count(distinct(case when v.age_y >= 60 then d.vn  end) ) as age_60more
from dtmain d
left outer join vn_stat v on v.vn = d.vn
left outer join hospcode h on h.hospcode=v.hospsub
where d.vstdate between '2013-01-01' and '2013-01-31' and v.hospmain=10874 and hospsub<>""
group by v.hospsub