select count(*),t.分組字段 from (
select t.* ,to_char(t.時間,'HH24') stime,to_char(t.時間,'HH24mi') fz,to_char(時間,'d')
from A t
where 時間>=to_date('2019-12-01','yyyy-MM-dd') and ghsj=to_date('2019-12-31','yyyy-MM-dd') and to_char(時間,'d')='2'
) where stime in ('08','09','10','11','12') and fz>=0800 a
group by T.分組字段
to_char(時間,'d') 取當前時間是星期幾 每星期第一天為周日
to_char(t.時間,'HH24mi') 取當前時間的小時分
o_char(t.時間,'HH24') 取當前時間的小時