Ancat Dubher
Ancat Dubher

Reputation: 111

In Q, how do I get the rows for the last X minutes from a Kdb table?

I have a table with price info. And building a front-end functionality that allows the user to see all prices from the last X minutes, where user specifies X.

How do I query this in q?

Upvotes: 0

Views: 884

Answers (2)

S.Stewart
S.Stewart

Reputation: 611

Let's say your table is called table. You could create a function f which takes one argument x:the number of minutes previously you want to select from.

q)f:{select price from table where time within (.z.p-`minute$x;.z.p)}

Then, for example to get price info from the last 15 minutes you would do:

q)f[15]

Upvotes: 5

Matthew Leonard
Matthew Leonard

Reputation: 126

Assuming your table is named trades, and the trades table has a time column you can use the following function to achieve the desired output:

q){select from trades where time >= .z.n-`minute$x}

Upvotes: 5

Related Questions