MAX , MIN query

https://learninghub.kx.com/forums/topic/max-min-query

Hello all,

I am working on a problem with HDB where I have t+1 intraday data , and I want the  MAX,MIN of each Symbol each mentioned by time shown in image , I can get data with interval using XBAR .But i want as per data logged in system.

I attached image for reference

EX.
SYM   Price   time
A         53.4     00:00:12.123
A         42.4     00:00:13.465
B         78.2      00:00:15.123
B         45.2      00:00:16.123

OUT

SYM  Price  time
A        53.4    00:00:12.123
A        53.4    00:00:13.465
B        78.2     00:00:15.123
B        78.2      00:00:16.123

Data is mixed and I have approach where I can use different variables and combine it,

but can we solve it in 1 query


 

You can use maxs and mins to compute the running maximum/minimum by sym.


q)t1:([]sym:`A`A`B`B;price:53.4 42.4 78.2 45.2;time:00:00:12.123 00:00:13.465 00:00:15.123 00:00:16.123)
q)t1
sym price time        
----------------------
A   53.4  00:00:12.123
A   42.4  00:00:13.465
B   78.2  00:00:15.123
B   45.2  00:00:16.123

q)update maxPrice:max maxs price,minPrice:min mins price by sym from t1
sym price time maxPrice minPrice
----------------------------------------
A 53.4 00:00:12.123 53.4 42.4
A 42.4 00:00:13.465 53.4 42.4
B 78.2 00:00:15.123 78.2 45.2
B 45.2 00:00:16.123 78.2 45.2