select count(*),to_date(t.sent_bg_time,'yyyy-mm-dd hh24') as 时间段
from table_history_201407 t
where t.sent_bg_time between to_date('20140723','yyyymmdd') and to_date('20140723','yyyymmdd')+0.99999
group by to_date(t.sent_bg_time,'yyyy-mm-dd hh24')
from table_history_201407 t
where t.sent_bg_time between to_date('20140723','yyyymmdd') and to_date('20140723','yyyymmdd')+0.99999
group by to_date(t.sent_bg_time,'yyyy-mm-dd hh24')
from table_history_201407 t
where trunc(t.sent_bg_time)=to_date('20140723','yyyymmdd')
group by to_char(t.sent_bg_time,'hh24')
谢谢 但有提示文字与格式字符串不匹配 sent_bg_time字段格式2014/7/23 00:00:00
sent_bg_time不是date类型的吗?再对他to_date没有什么意义
这么写应该是把sent_bg_time当文本类型处理了
如12:10 和12:11分组的时候会分组成两条,达不到统计的效果
to_char(sent_bg_time,‘HH24’)之后,两个时间 就都转化为‘12’,分组统计就统计到一起了
from table_history_201407 t
where trunc(t.sent_bg_time)=to_date('20140723','yyyymmdd')
group by to_char(t.sent_bg_time,'hh24')