Hi q-Gods,
Please, help needed! I know what I need to do but I have no idea how to do it in q. I have given my absolute best and have spent 2 days trying, but nothing seem to work out.
I have a table t with an empty RM (running minimum) column which needs to be filled with running minimum of col “px”
record id acn px RM
0 1 1 15
1 2 1 20
2 3 1 10
3 4 1 11
4 3 0 10
5 5 1 13
6 4 0 11
7 6 1 17
.. … .. …
Each ID in the table can have 2 acn’s, either acn=1 (order submitted) or acn=0 (order cancelled). I am looking to run a running minimum in RM column. However, whenever an ID has acn=0, the the according price is no longer registered in the system. In this case, next minimum takes its place. Allow me to demonstrate with table t.
“Record” table is just an index of each row/record and is used purely this example, I do not have have this col in my table t.
record id acn px RM
0 1 1 15 15
1 2 1 20 15
2 3 1 10 10
3 4 1 11 10
Record 4 says: ID=3 has acn=0, which means this orders has been cancelled and is no longer in the system. Its px is ignored from here on. This means that the next-in-order-minimum is 11. Of course to find this next in order minimum, ‘mins’ has to be rerun on col px up until this point (but not including record 4), but this time without, or ignoring, record 2 where ID=3 is registered. Hence (continuing from record 4)
record id acn px RM
4 3 0 10 11
5 5 1 13 11
Again, record 6 indicates that ID=4 has acn=0 and therefore is cancelled and its price is no longer registered in the system. Yet again, “mins” has to be run up til this point (but not inclusive record 6), but this time ignoring not only records where ID=3, but also where ID=4.
record id acn px RM
6 4 0 11 13
7 6 1 17 13
This is the result I am after:
record id acn px RM
0 1 1 15 15
1 2 1 20 15
2 3 1 10 10
3 4 1 11 10
4 3 0 10 11
5 5 1 13 11
6 4 0 11 13
7 6 1 17 13
Absolutely no idea how to implement this in q. I would definitely give me hard time in other programming languages that I am pretty familiar already too…
As always, if you have a minute or two your time and effort is very ‘extremely’ appreciated.
Regards,
VA.