-4

The output should be the last column (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

Thanks for your help. SM

Ullas
  • 11,450
  • 4
  • 33
  • 50

2 Answers2

0

I am not sure the below query is perfect or not , but this solution helps you to find out the correct solution !

select
    EMPLOYEE, MONTH, YEAR ,SALARY ,sum(SALARY) over(order by EMPLOYEE) as Cum_Sal
from emp
Usman
  • 1,983
  • 15
  • 28
0

This is the answer you were looking for.

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
DJKarma
  • 172
  • 9