How to get step size of elements in a column in kdb

Viewed 75

I have a table like

q)t
ex mo 
------
a  -10
a  -5 
a  0  
a  5  
a  10 
b  -30
b  -20
b  -10
b  0  
b  10 
b  20 
b  30 

table gen query -

q)t:([] ex:(5#`a),7#`b; mo:-10 -5 0 5 10 -30 -20 -10 0 10 20 30)

I'm trying to get min mo, max mo and step size of `mo by exp from t.

Expected Output -

ex| min_mo max_mo  step_size
--| -------------------------
a | -10    10      5
b | -30    30      10

I'm not clear on how to get step size, below solution works but not optimised. Would you please suggest an optimized solution?

q)select min_mo:min mo, max_mo:max mo, step_size:last deltas mo by ex from t
0 Answers
Related