BMS-HOSxP Community
		HOSxP => Report Exchange => ข้อความที่เริ่มโดย: Manit ที่ กรกฎาคม 07, 2010, 09:20:40 AM
		
			
			- 
				จนท. PCU อยากได้รายงานจำนวนอัตราการวางแผนครอบครัว ที่ดึงข้อมูลมาจากบัญชี6น่ะครับ
 
 หน้าตามแบบที่แนบมครับ อ.ท่านใด มีก็ขออนุเคราะห์หน่อยครับ  ;D
- 
				ขอบคุณครับ
			
- 
				  ขอบคุณครับ 
 ยังไม่มีใครขอมาหรอก แต่ เสนอให้ก่อนเขาคงไม่ปฏิเสธกลับมาหรอกนะครับ
 หรือว่าที่ไหนปธิเสธในสิ่งที่ผู้หวังดีมอบให้
- 
				ขอด้วยคนครับท่าน
 
 ขอขอบคุณล่วงหน้าเลยครับ อาจารย์
- 
				แบบนี้คงพอใช้ได้นะครับ
			
- 
				ขอบคุณ saiphon แต่พอดีผมทำได้ก่อนแล้วครับ ขอบคุณ 
			
- 
				รบกวนขอแบบที่เลือกช่วงวันที่ได้ ได้รึเปล่าคับ
			
- 
				 :)รบกวนขอแบบที่เลือกช่วงวันที่ได้ ได้รึเปล่าคับ
 
 
 มีแบบนี้ ลองทดสอบดู
- 
				ขอบคุณมากครับ เดี่ยวจะขอทดสอบดู
			
- 
				ลองแบบนี้ได้อีกแบบครับ 
			
- 
				set @ds1:='2012-10-1';
 set @ds2:='2013-9-30';
 select cast(a.village_moo as decimal) moo,a.village_name name,b.*
 ,if(b.target=0,0,b.total/b.target*100) percent
 from village a
 left join (select v.village_id
 ,count(distinct p.cid) target
 ,count(distinct if(s.women_service_id=1 and s.women_birth_control_id>0,s.person_women_service_id,null)) total
 ,count(distinct if(s.women_birth_control_id=0 or s.women_birth_control_id is null,s.person_women_service_id,null)) FP0
 ,count(distinct if(s.women_birth_control_id=1,s.person_women_service_id,null)) FP1
 ,count(distinct if(s.women_birth_control_id=2,s.person_women_service_id,null)) FP2
 ,count(distinct if(s.women_birth_control_id=3,s.person_women_service_id,null)) FP3
 ,count(distinct if(s.women_birth_control_id=4,s.person_women_service_id,null)) FP4
 ,count(distinct if(s.women_birth_control_id=5,s.person_women_service_id,null)) FP5
 ,count(distinct if(s.women_birth_control_id=6,s.person_women_service_id,null)) FP6
 ,count(distinct if(s.women_birth_control_id=7,s.person_women_service_id,null)) FP7
 from person p
 left join village v on p.village_id=v.village_id
 left join person_women w on p.person_id=w.person_id
 left join person_women_service s on w.person_women_id=s.person_women_id and s.service_date between @ds1 and @ds2 and s.women_service_id=1
 where p.sex=2
 and p.marrystatus=2
 and p.house_regist_type_id in (1,3)
 and timestampdiff(year,p.birthdate,@ds1) between 15 and 44
 group by v.village_id) b on a.village_id=b.village_id
 order by 1
- 
				set @ds1:='2012-10-1';
 set @ds2:='2013-9-30';
 select a.women_birth_control_id id,a.women_birth_control_name name
 ,ifnull(b.cc,0) Total
 ,ifnull(b.incase,0) incase
 ,ifnull(b.invisit,0) invisit
 ,ifnull(b.outcase,0) outcase
 ,ifnull(b.outvisit,0) outvisit
 from women_birth_control a
 left join (select s.women_birth_control_id,count(*) cc
 ,count(distinct if(v.village_moo<>0,p.cid,null)) incase
 ,count(if(v.village_moo<>0,p.cid,null)) invisit
 ,count(distinct if(v.village_moo=0,p.cid,null)) outcase
 ,count(if(v.village_moo=0,p.cid,null)) outvisit
 from person_women_service s
 left join person_women w on w.person_women_id=s.person_women_id
 left join person p on p.person_id=w.person_id
 left join village v on p.village_id=v.village_id
 where s.service_date between @ds1 and @ds2
 and s.women_service_id=1
 group by s.women_birth_control_id) b on a.women_birth_control_id=b.women_birth_control_id
 where a.women_birth_control_id>0
 order by 1