oracle++统计函数,oracle统计函数

Windowing-ClauseThe windowing clause gives us a way to define a sliding or anchored window of data, on which the analytic function will operate, within a group. This clause can be used to have the analytic function compute its value based on any arbitrary sliding or anchored window within a group.

;例如:

over(order by salary) 按照salary排序进行累计,order by是个默认的开窗函数

over(partition by deptno)按照部门分区

over(order by salary range between 50 preceding and 150 following)

每行对应的数据窗口是之前行幅度值不超过50,之后行幅度值不超过150

over(order by salary rows between 50 preceding and 150 following)

每行对应的数据窗口是之前50行,之后150行

over(order by salary rows between unbounded preceding and unbounded following)

每行对应的数据窗口是从第一行到最后一行,等效:

over(order by salary range between unbounded preceding and unbounded following)例子:

CREATE TABLE vote_count (

submit_date  DATE NOT NULL,

num_votes    NUMBER NOT NULL);

INSERT INTO vote_count VALUES (TRUNC(SYSDATE)-4, 100);

INSERT INTO vote_count VALUES (TRUNC(SYSDATE)-3, 150);

INSERT INTO vote_count VALUES (TRUNC(SYSDATE)-2, 75);

INSERT INTO vote_count VALUES (TRUNC(SYSDATE)-3, 25);

INSERT INTO vote_count VALUES (TRUNC(SYSDATE)-1, 50);

COMMIT;

SELECT * FROM vote_count;

1 2007-6-28 100

2 2007-6-29 150

3 2007-6-29 25

4 2007-6-30 75

5 2007-7-1 50统计每天提交数量在所有中的百分比:select submit_date,num_votes/sum(num_votes)over() from vote_count 统计每次提交的数据占本天的百分比:select submit_date,num_votes/sum(num_votes)over(partition by submit_date) from vote_count 统计本次提交以及之前所有提交的总量:select submit_date,sum(num_votes)over(order by submit_date) from vote_count 或select submit_date,sum(num_votes)over(order by submit_date rows between unbounded preceding and 0 following) from vote_count

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值