select o.vstdate ,count(o.vn) as morning ,count(a.vn) as afternoon ,count(b.vn) as nigth
from ovst o
left outer join ovst a on a.vn=o.vn and a.vsttime between'16:00:00' and '23:59:59'
left outer join ovst b on b.vn=o.vn and b.vsttime between'00:00:00' and '07:59:59'
where o.vstdate between '2009-05-01' and'2009-05-31'
and o.vsttime between'08:00' and '15:59:59'
group by o.vstdate
:Dมันออกจะเฉพาะ ช่วงเช้า ครับ บ่ายกับดึกไม่ออก