BMS-HOSxP Community
		HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: Knott ที่ ตุลาคม 27, 2008, 08:22:41 AM
		
			
			- 
				ผมจะดึงข้อมูล อันดับโรคนอกเวลาที่มา ER ลองเขียนคำสั่งแล้วไม่ขึ้น วอนผู้รู้ช่วยดูให้หน่อยครับว่าผิดตรงไหน
select a.main_pdx,count(a.main_pdx) as pdx_count ,i.name as icdname 
from vn_stat a
join ovst v on v.vn=a.vn and v.cur_dep="012"
left outer join icd101 i on i.code=a.main_pdx 
where a.vstdate between '2008-09-01' and '2008-09-30'
and v.vsttime between '20:30:00' and '08:29:59'
and a.main_pdx<>'' and a.main_pdx is not null 
group by a.main_pdx,i.name 
order by pdx_count desc 
limit 20 
ขอบคุณครับ
			 
			
			- 
				
...ลองแบบนี้น่าจะพอได้นะครับ....
select a.main_pdx,count(a.main_pdx) as pdx_count ,i.name as icdname
from vn_stat a
join ovst v on v.vn=a.vn
left outer join icd101 i on i.code=a.main_pdx and v.cur_dep="012"
where a.vstdate between'2008-09-01' and '2008-09-30'
and (v.vsttime between '20:30:00' and '23:59:59' or v.vsttime between '00:00:00' and '08:29:59')
and  (a.main_pdx<>'' or  a.main_pdx is not null)
group by a.main_pdx,i.name
order by pdx_count desc
limit 20
.... :D....
			 
			
			- 
				select มาทีละตารางก่อน
อาจไม่มีข้อมูลตามเงื่อนไข
			 
			
			- 
				ขอบคุณมากครับ ต้องใช้ or เชื่อมเวลาที่ข้ามวันด้วยนี่เอง  ;D