1.นอก/ในเวลา
select count(x.vn) total
,sum(dayofweek(x.request_date) in (1,7)
or h.holiday_date is not null
or x.request_time<'08:00:00'
or x.request_time>'16:00:00') outtime
,sum(!(dayofweek(x.request_date) in (1,7)
or h.holiday_date is not null
or x.request_time<'08:00:00'
or x.request_time>'16:00:00')) intime
from xray_report x
left join holiday h on h.holiday_date=x.request_date
where x.request_date between '2013-1-1' and '2013-1-31'
2.OPD/IPD
select count(x.vn) total
,sum(length(an)<>9) 'OPD'
,sum(length(an)=9) 'IPD'
from xray_report x
where x.request_date between '2013-1-1' and '2013-1-31'