select year(vstdate) 'year'
,cast(monthname(vstdate) as char(30)) 'month'
,cast(dayname(vstdate) as char(20)) 'day'
,sum(if(main_dep='027',1,0)) 'Screen'
,sum(if(main_dep='011',1,0)) 'ER'
,count(vn) 'amount'
from ovst
where vstdate between '2010-1-1' and '2010-1-31'
and vsttime between '08:30:00' and '12:30:00'
group by year(vstdate),month(vstdate),dayofweek(vstdate)
order by year(vstdate),month(vstdate),dayofweek(vstdate)
ประมาณนี้มั๊ย