欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

oracle列递归累加sql代码实例

程序员文章站 2022-03-14 08:31:36
查询压岁钱表age_money select * from age_money; year1 money 2001 10 2002 20 2003 20...

查询压岁钱表age_money

select * from age_money;
year1 money
2001  10
2002  20
2003  20
2004  5
2005  10

递归累加

WITH T AS (
select year1,money from age_money where order by year1
)
SELECT T.year1,T.money, SUM(T.money) OVER(ORDER BY T.year1) as Recursion_Accumulate FROM T
year1 money RECURSION_ACCUMULATE
2001  10    10
2002  20    30
2003  20    50
2004  5     55
2005  10    65