oracle SQL语句中怎么查询一个月内固定时间段的数据,比如9月1号到10月1号每天的八点到九点的呼叫数目

2024-12-04 11:17:51
推荐回答(2个)
回答1:

使用Oracle 函数extract(fmt from d)获取日期中的特定部分:
select count(*) from table where
SQL> select * from table where createdate
between to_date('2010-9-1','yyyy-MM-dd') and to_date('2010-10-1','yyyy-MM-dd')
and EXTRACT(hour from createdate) between '8:00' and '9:00';

回答2:

select a.日期,count(*) from 表名 a
where to_char(a.具体时间,'HH') <= '21' and to_char(a.具体时间,'HH')>='20'
group by a.日期
having to_char(a.日期,'YYYY-MM-DD')<='2011-10-01' and to_char(a.日期,'YYYY-MM-DD')>='2011-09-01'