oracle 时间分段查询
2016-04-15 14:54
483 查看
/*建表*/
create table test1(serviceid number,
callerno number,
begintime date,
endtime date
);
/*设置数据库时间格式*/
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
/*某个时段查询*/
select to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + (n - 1) / 48 sec_begin,
to_date('2009-06-01 00:00:00', 'yyyy-mm-ddhh24:mi:ss') + n / 48 sec_end,
count(callerno) callnum,
nvl(sum(endtime - begintime),0) * 24 * 60 * 60 "calllength(s)"
from test1 t, (select rownum n from dual connect by level < = 48) integers
where t.begintime
between
to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + (n - 1) / 48
and
to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + n / 48
group by n;
/*全天分段查询*/
select to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + (n - 1) / 48 sec_begin,
to_date('2009-06-01 00:00:00', 'yyyy-mm-ddhh24:mi:ss') + n / 48 sec_end,
count(callerno) callnum,
nvl(sum(endtime - begintime),0) * 24 * 60 * 60 "calllength(s)"
from test1 t
right join (select rownum n from dual connect by level < = 48) integers
on t.begintime
between
to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + (n - 1) / 48
and
to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + n / 48
group by n;
create table test1(serviceid number,
callerno number,
begintime date,
endtime date
);
/*设置数据库时间格式*/
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
/*某个时段查询*/
select to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + (n - 1) / 48 sec_begin,
to_date('2009-06-01 00:00:00', 'yyyy-mm-ddhh24:mi:ss') + n / 48 sec_end,
count(callerno) callnum,
nvl(sum(endtime - begintime),0) * 24 * 60 * 60 "calllength(s)"
from test1 t, (select rownum n from dual connect by level < = 48) integers
where t.begintime
between
to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + (n - 1) / 48
and
to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + n / 48
group by n;
/*全天分段查询*/
select to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + (n - 1) / 48 sec_begin,
to_date('2009-06-01 00:00:00', 'yyyy-mm-ddhh24:mi:ss') + n / 48 sec_end,
count(callerno) callnum,
nvl(sum(endtime - begintime),0) * 24 * 60 * 60 "calllength(s)"
from test1 t
right join (select rownum n from dual connect by level < = 48) integers
on t.begintime
between
to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + (n - 1) / 48
and
to_date('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + n / 48
group by n;
相关文章推荐
- oracle执行计划
- 探秘Oracle表空间、用户、表之间的关系
- win64 位系统运行32位Oracle客户端
- Oracle并行处理 /*+ parallel(A 8) parallel(B 8) parallel(C 8) parallel(D 8) */
- oracle lag与lead分析函数简介
- oracle权限with admin option和with grant option的用法
- Oracle 数据库基础学习 (八) PL/SQL综合练习
- ORACLE 闪回恢复区(Flashback recovery area)与undo tablespace
- Oracle 11g RAC搭建(VMware环境)
- Oracle问题之ORA-12560TNS:协议适配器错误
- Oracle问题之字符集问题,登陆sqlplus出现问号
- Oracle问题之ORA-01031权限不足
- oracle引入索引的目的
- Oracle BI Server DNS 配置错误集
- oracle 行转列,列转行
- Oracle--通配符、Escape转义字符、模糊查询语句
- SQL-Oracle-创建表空间,用户,授权
- oracle client与ODAC的字符集
- SQL-Oracle-创建Dblink
- Oracle 创建分区表