2008-01-07
oracle中over()开窗函数的理解
关键字: 分析函数 analytic query functions
开窗函数指定了分析函数工作的数据窗口大小,这个数据窗口大小可能会随着行的变化而变化,举例如下:
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)
eg.
select * from
(
select p.deal_no,p.step_id,p.charge_id,p.dr_acc_no,
sum(p.dr_origin_amt)
over (partition by p.deal_no,p.step_id,p.dr_acc_no order by p.charge_id) as a,
dense_rank()
over (partition by p.deal_no,p.step_id,p.dr_acc_no order by p.charge_id) as b
from ixqdbaci p
where p.entity='002' and p.charge_id not like '99%'
and p.deal_no like '00779010010612%'
) where b=1
sum中的over()加上order by后会变成递增累加,而不是分组的所有值sum,所以在这条sql中应该把a列的oder by p.charge_id删除,b列的dense_rank是为了区分同一组的不同行,并且order by是不可少的。
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)
eg.
select * from
(
select p.deal_no,p.step_id,p.charge_id,p.dr_acc_no,
sum(p.dr_origin_amt)
over (partition by p.deal_no,p.step_id,p.dr_acc_no order by p.charge_id) as a,
dense_rank()
over (partition by p.deal_no,p.step_id,p.dr_acc_no order by p.charge_id) as b
from ixqdbaci p
where p.entity='002' and p.charge_id not like '99%'
and p.deal_no like '00779010010612%'
) where b=1
sum中的over()加上order by后会变成递增累加,而不是分组的所有值sum,所以在这条sql中应该把a列的oder by p.charge_id删除,b列的dense_rank是为了区分同一组的不同行,并且order by是不可少的。
发表评论
- 浏览: 394527 次
- 性别:

- 来自: 上海

- 详细资料
搜索本博客
我的相册
Gmail
共 8 张
共 8 张
最新评论
-
JIRA不完全手册
楼主,发一份完整的资料给我吧 xwj1003@yahoo.com.cn
-- by volking -
java encoding参考
Good ,thanks.
-- by zuowei -
有多少异常可以重来
我今天也遇到这个问题,才搜到这个帖子~ 还没有解决,等恢复哦
-- by javamanlcy007 -
有多少异常可以重来
这个错误解决了,又抱了别的错误~
-- by iceworld4143 -
有多少异常可以重来
解释不太懂,我也遇到这个问题了,可是我没用ant。 :cry: 等回 ...
-- by iceworld4143






评论排行榜