DolphinDB: how to perform iterative operations based on previous results using SQL statements?

28 Views Asked by At

I intend to calculate a column named “position“ with an initial value of 0. The calculation logic is: when “position” = 0 and “ov95” = 1, “position” returns 1; when “position” = 1 and “ov70” = 0, “position” returns 0. That is, the calculation of “position“ in the k-th row requires the value of “position“ in the (k-1)th row. Is it possible to achieve this using SQL?

enter image description here

1

There are 1 best solutions below

0
On

I think accumulate could perform your calculation: implement your position calucation function, and then input your table (which contains ov70 and ov95 columns) and the init value (0 in your case). Then you will get the position vector.