Oracle 分析函数分组累加!
用户号码 登陆时间
1300000000 2010-01-01
1300000001 2010-01-01
1300000002 2010-01-02
1300000001 2010-01-02
1300000003 2010-01-03
1300000002 2010-01-03
1300000004 2010-01-04
1300000003 2010-01-04
1300000004 2010-01-02
1300000006 2011-01-04
1300000001 2011-01-04
剔除重复登陆的用户,只计算统计时间内用户的第一次登陆记录。然后每天累加用户数。
select b.statusdate,
sum(times) over(partition by trunc(b.statusdate, 'mm') order by b.statusdate)
from (select a.statusdate, count(1) times
from (select phone, trunc(min(statusdate), 'dd') statusdate
from test_table t
where t.statusdate >= to_date('20100101', 'yyyymmdd') --统计开始时间
and t.statusdate < to_date('20100201', 'yyyymmdd')
group by phone) a --取用户第一条记录时间
group by a.statusdate) b
由统计开始和结束时间控制数据源。trunc(b.statusdate, 'mm') 控制累加的范围,如果是月则表示按月累计,也就是每月的第一次重新统计。
由于受到trunc(b.statusdate, 'mm') 只能按年,月,日累加所以如果数据源跨年则不能一累加。如果需要一直累加则:
select b.statusdate,
sum(times) over(partition by b.part order by b.part,b.statusdate)
from (select a.part,a.statusdate, count(1) times
from (select 1 part,phone, trunc(min(statusdate), 'dd') statusdate
from test_table t
where t.statusdate >= to_date('20100101', 'yyyymmdd') --统计开始时间
and t.statusdate < to_date('20110201', 'yyyymmdd')
group by phone) a --取用户第一条记录时间
group by a.statusdate,a.part) b
增加一个临时字段表示累加范围,例如:1表示数据统计第一次进行累加数据统计,然后按这一次的所有数据进行去重和累叫。
相关文档:
oracle表空间操作详解
1
2
3作者: 来源: 更新日期:2006-01-04
5
6
7建立表空间
8
9CREATE TABLESPACE data01
10DATAFILE '/ora ......
Oracle 内存结构如下图:
1:实例(Instance)
在一个中,每一个运行的Oracle数据库都与一个数据库实例相联系,实例是我们
访问数据库的手段。
实例在操作系统中用ORACLE_SID来标识,在Oracle中用参数INSTANCE_NAME来标识,
它 ......
Oracle TNS简述
什么是TNS?
TNS是Oracle Net的一部分,专门用来管理和配置Oracle数据库和客户端连接的一个工具,在大多数情况下客户端和数据库要通讯,必须配置TNS,当然在少数情况下,不用配置TNS也可以连接Oracle数据库,比如通过JDBC.如果通过TNS连接Oracle,那么客户端必须安装Oracle client程序.
TNS有那些配置文件 ......
每隔几秒钟listener日志中就出现一次该错误的记录,即使是在没有人使用的情况下也是如此,不过并没有发现客户端机器不能正常连接数据库的情况。
Oracle关于TNS-12502错误的解释:
Error: ORA-12502 / TNS-12502
Text: TNS:listener received no CONNECT_DATA from client
Cause: No CONNECT_DATA was ......
数据库的内存结构:
Memory structures are allocated to the Oracle instance when the instance is started.
The two major memory structures are known as the System Global Area(Also called the shared
Global Area)and the Program Global Area(also called the Private Global Area or the ......