输出应该是最后一列(Cum_Sal)。
EMPLOYEE MONTH YEAR SALARY Cum_Sal
A JAN 2016 2000 2000
A FEB 2016 2000 4000
A MAR 2016 2000 6000
A APR 2016 3000 9000
A MAY 2016 3000 12000
A JUN 2016 3000 15000
A JUL 2016 3000 18000
A AUG 2016 3000 .
A SEP 2016 3000 .
A OCT 2016 3000
A NOV 2016 3000
A DEC 2016 3000
A JAN 2017 3000 3000
A FEB 2017 3000 6000
A MAR 2017 3000 9000
A APR 2017 5000 .
A MAY 2017 5000 . (SO ON)
A JUN 2017 5000
A JUL 2017 5000
A AUG 2017 5000
感谢您的帮助。 SM
答案 0 :(得分:0)
我不确定以下查询是否完美,但此解决方案可帮助您找到正确的解决方案!
select
EMPLOYEE, MONTH, YEAR ,SALARY ,sum(SALARY) over(order by EMPLOYEE) as Cum_Sal
from emp
答案 1 :(得分:0)
这是您要寻找的答案。
select EMPLOYEE, MONTH, YEAR ,SALARY ,sum(SALARY) over (partition by YEAR order by SALARY rows between unbounded preceding and current row ) as Cum_Sal from emp