Sunday, August 3, 2014

kdb: how to select the max of 2 columns

with sql, we just simply

select max(col1, col2) from t

with kdb, we will need to something like:

q)select [5] from t
time         sym  bid   ask  
-----------------------------
09:30:00.386 IBM  50.12 51.69
09:30:00.754 IBM  50.69 51.02
09:30:00.871 AAPL 50.2  51.4 
09:30:01.548 AAPL 50.84 51.28
09:30:01.921 GOOG 50    51.82
q)select [5] from update greater:max each flip (bid; ask) from t
time         sym  bid   ask   greater
-------------------------------------
09:30:00.386 IBM  50.12 51.69 51.69  
09:30:00.754 IBM  50.69 51.02 51.02  
09:30:00.871 AAPL 50.2  51.4  51.4   
09:30:01.548 AAPL 50.84 51.28 51.28  
09:30:01.921 GOOG 50    51.82 51.82  

No comments:

Post a Comment