Search code examples
kdb

how to use multiple arguments in kdb where query?


I want to select max elements from a table within next 5, 10, 30 minutes etc. I suspect this is not possible with multiple elements in the where clause. Using both normal < and </: is failing. My code/ query below:

`select max price from dat where time</: (09:05:00; 09:10:00; 09:30:00)`

Any ideas what am i doing wrong here? The idea is to get the max price for each row within next 5, 10, 30... minutes of the time in that row and not just 3 max prices in the entire table.

select max price from dat where time</: time+\:(5 10 30)

This won't work but should give the general idea.

To further clarify, i want to calculate the max price in 5, 10, 30 minute intervals from time[i] of each row of the table. So for each table row max price within x+5, x+10, x+30 minutes where x is the time entry in that row.


Solution

  • This works but takes a lot of time. For 20k records, ~20 seconds, too much!. Any way to make it faster

     dat: update tmlst: time+\:mtf*60 from dat;
     dat[`pxs]: {[x;y] {[x; ts] raze flip raze {[x;y] select min price from x where time<y}[x] each ts }[x; y`tmlst]} [dat] each dat;