Skip to content
Advertisement

Add rows accumulated by current month

Is there a way to translate my hard coded SQL script into a dynamic?

My problem with this code is that, it still adding the SEPT-DEC it should be zero since we are not yet covered this month

My table

enter image description here

Expected Result:

Starts from JAN then Added the succeeding covered months.

enter image description here

Advertisement

Answer

You can UNPIVOT your data, use the window function sum() over() to calculate the running total and then PIVOT the results.

Example

Results

enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement