Skip to content
Advertisement

Calculate cumulative product value

I have the following database table:

I would like to update the Index value using the following formula:

Expected Result: (Index to be calculated order by Date asc)

How can I do this using SQL? I tried the following query but getting an error:

Windowed functions cannot be used in the context of another windowed function or aggregate.

Advertisement

Answer

Thinking mathematically, the result that you want is equivalent to this product:

where a1, a2, a3 are the values of the column [Return].

This product can be obtained by:

and you can do this in sql like this:

See the demo.

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