当前位置:首页 » 编程语言 » oraclesql查询时间段

oraclesql查询时间段

发布时间: 2025-02-28 16:34:15

① oracle sql语句中怎么查询一个月内固定时间段的数据,比如9月1号到10月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';

② oracle数据库 查询时间段一年的数据的SQL语句怎么写。 比如查询一年白班时间(八点至五点)的数据

使用to_char()将时间字段转换成字符串然后再做。例如
select * from table1
where to_char(t,'HH24')>=8 and to_char(t,'HH24')<17

③ oracle 查询一段时间内每一天的统计数据sql怎么写

可以写一个简单的procere来实现,原理是遍历日期范围,并查询日期资料笔数,写入表。
数据源表test03
1 2016-06-01 1
2 2016-06-02 1
3 2016-06-05 1
4 2016-06-04 1
5 2016-06-04 1

procere代码如下:
create or replace procere loop_by_date(pbeg_tim in varchar2,--开始日期
pend_tim in varchar2,--结束日期
errmessage out varchar2) is

nCount number(10); --总天数
i_point number(10); --当天
is_zero number(10); --当天是否有记录
begin
nCount := 0;
i_point := 0;
is_zero := 0;

select ROUND(to_date(pend_tim, 'yyyy-mm-dd') -
to_date(pbeg_tim, 'yyyy-mm-dd'))
into nCount
from al;

delete from test02;

<<fst_loop>>
loop

select count(*)
into is_zero
from test03
where date1 =
to_char(to_date(pbeg_tim, 'yyyy-mm-dd') + i_point, 'yyyy-mm-dd');

insert into test02
(date01, nccount)
values
(to_char(to_date(pbeg_tim, 'yyyy-mm-dd') + i_point, 'yyyy-mm-dd'),
is_zero);

i_point := i_point + 1;
exit fst_loop when i_point >= nCount;
end loop fst_loop;
--end;

end loop_by_date;

传入参数"2016-06-01"~~"2016-06-10"并执行,结果写入test02为:
1 2016-06-01 1
2 2016-06-02 1
3 2016-06-03 0
4 2016-06-04 2
5 2016-06-05 1
6 2016-06-06 0
7 2016-06-07 0
8 2016-06-08 0
9 2016-06-09 0

④ sql 查询某字段的某段内容

如果 表结构是这样的话 text ,sdate 的话 可以使用
select test||sdate from book where sdate = (select min(sdate) from book where text ='张三')

热点内容
y和m驱动模块编译区别 发布:2025-02-28 21:08:04 浏览:339
互联网云服务器端口号 发布:2025-02-28 21:07:57 浏览:793
android蓝牙版本 发布:2025-02-28 21:07:17 浏览:762
php的输出函数 发布:2025-02-28 21:02:09 浏览:224
数据库统计信息 发布:2025-02-28 20:58:19 浏览:173
安卓微信区王者哪个地区分低 发布:2025-02-28 20:52:57 浏览:128
python语言的合法命名 发布:2025-02-28 20:40:15 浏览:863
c语言给数组整体赋值 发布:2025-02-28 20:30:06 浏览:59
装修公司文件存储解决方案 发布:2025-02-28 20:30:06 浏览:533
如何查看计算机主板配置 发布:2025-02-28 20:28:38 浏览:308