Query ออกมา ผลลัพธ์ที่ได้ ก็ ok ครับ แต่ช้าเว่อๆเลย อยากทำให้มันเร็วกว่านี้ พอจะปรับตรงได้ได้มั่งครับ
อันนี้เตียงพิเศษ
select w.snap_date,count(w.an) as cc,weekday(w.snap_date)+1
from ward_admit_snapshot w
left outer join ipt_food_menu ifm on ifm.an = w.an
where w.snap_date between "2013-01-01" and "2013-01-01"
and w.ward <> "03"
and w.an = (select d.an from iptadm d where d.an = w.an and (d.bedtype = "01" or d.bedno is null or d.bedno = " ") limit 1)
and ifm.date_id = (weekday(w.snap_date)+1)
group by w.snap_date
เตียง สามัญ
select w.snap_date,count(w.an) as cc,weekday(w.snap_date)+1
from ward_admit_snapshot w
left outer join ipt_food_menu ifm on ifm.an = w.an
where w.snap_date between "2013-01-01" and "2013-01-01"
and w.ward not in ("08","09","16","20","21","22","03")
and w.an = (select d.an from iptadm d where d.an = w.an and (d.bedtype in ("00","02","03") or d.bedno is null or d.bedno = " ") limit 1)
and ifm.date_id = 2
group by w.snap_date