oracle 怎样实现每2小时分组对数据统计,该如何处理
发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
oracle 怎样实现每2小时分组对数据统计
现有视图如下:
cwar trdt num
A 2015-03-01 08:05:27 3
A 2015-03-01 08:25:37 2
A 2015-03-01 08:33:15 3
A 2015-03-01 09:04:09 5
A 2015-03-01 10:17:06 4
A 2015-03-01 10:22:09 1
A 2015-03-01 11:39:00 3
请问大侠,同一日期下每两小时对num进行分组统计要如何写,先行谢过!
------解决思路----------------------
with t as
( select 'A' as cwar, to_date('2015-03-01 08:05:27','yyyy-mm-dd hh24:mi:ss') as trdt, 3 as num from dual
union all select 'A', to_date('2015-03-01 08:25:37','yyyy-mm-dd hh24:mi:ss'), 2 from dual
union all select 'A', to_date('2015-03-01 08:33:15','yyyy-mm-dd hh24:mi:ss'), 3 from dual
union all select 'A', to_date('2015-03-01 09:04:09','yyyy-mm-dd hh24:mi:ss'), 5 from dual
union all select 'A', to_date('2015-03-01 10:17:06','yyyy-mm-dd hh24:mi:ss'), 4 from dual
union all select 'A', to_date('2015-03-01 10:22:09','yyyy-mm-dd hh24:mi:ss'), 1 from dual
union all select 'A', to_date('2015-03-01 11:39:00','yyyy-mm-dd hh24:mi:ss'), 3 from dual )
select t.cwar, b.trdt, sum(t.num) as num
from t,
( select level as rn, to_date('2015-03-01','yyyy-mm-dd') + (level - 1)/ 12 as trdt from dual connect by level <= 12 ) a,
( select level as rn, to_date('2015-03-01','yyyy-mm-dd') + (level)/ 12 as trdt from dual connect by level <= 12 ) b
where b.rn = a.rn
and t.trdt >= a.trdt
and t.trdt < b.trdt
group by t.cwar, b.trdt
order by 1,2
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
基于MATLAB实现的云模型计算隶属度
”云”或者’云滴‘是云模型的基本单元,所谓云是指在其论域上的一个分布...
-
在linux上安装oracle11G必须在图形界面才能安装吗?纯命令行下,安装linux时没有安装图形界面!
安装了redhat 6.3系统,但是安装系统是...
-
请教 primary key 使用 Varchar2 与 Char 差别有人知道吗 ?
从以前就有这个疑问,但碍于开 Table 的 KEY通常几乎都是有规则的,且固...
-
关于外键的建立问题
比如说我建立下面两个表
create table user(
id bigint(10) premary key auto_increment,
username varch...
-
PLSQL 新电脑装了 11g, 开启后找不到可以连接的资料库清单><?
旧电脑 Oracle Client → C:Oracle,这个我直接开 Pl/SQL 再登入帐...
-
我在aix 5.3 上创建oracle10g监听报错
Configuring Listener:LISTENER
ServiceAliasException: Could not save Service Alias: ...
-
ORACLE update 问题 新手求解答
有三张表A B C
B表的部分数据 复制给A
B表跟C表降序排列后假设他是一一对应的关系
现在想把...
-
存储过程执行报无效数字
存储过程
CREATE OR REPLACE PROCEDURE UpdatePiecesChn(pieceidStr in varchar2,
...
-
CE_现金银行总行分行设定详解(案例)
2014-07-14 Created By BaoXinjian
一、摘要
1. 设定银行总行
设定银行总行基本资料
设定银...
-
一个简单的报错,麻烦看看
函数如下,提示报错行 是: return str1;我实在搞不懂,麻烦指教一下
create or replace function qdn_lks_fi...