functions that return functions in a select statement

Hi,

I had a problem when applying a function to a select statement. For example, the following code works perfectly 

$[0;max;min] 1 2 3 4 5

but if put the function in a select statement, it doesn’t work,eg

q)sp

s  p  qty

---------

s1 p1 300

s1 p2 200

s1 p3 400

s1 p4 200

s4 p5 100

s1 p6 100

s2 p1 300

s2 p2 400

s3 p2 200

s4 p2 200

s4 p4 300

s1 p5 400

q)select $[1;max;min] qty from sp

'rank

[0] select $[1;max;min] qty from sp


Instead of putting the whole thing into {} like this

{[x;t] $[x;select max qty from t;select min qty from t]}[1;sp]

 

I’m just wondering is their a way to format the query properly that do the job but avoid putting everything into {}? 

Any ideas are greatly appreciated, thanks a lot!

Xinyu

I think Cond is not supported directly inside q-sql (https://code.kx.com/v2/ref/select/), you can use vector conditional instead

q)select enlist ?[1b;max;min]qty from t

qty


90

Or use a function/lambda

q)select {enlist $[1b;max;min]x}qty from t

qty


90

You could use following options:

q) select enlist {$[0;max;min] x} qty from sp

or

q) select enlist (max;min)[0] qty from sp

I think there's two issues:1. Use vector conditional (even if you only have a single boolean)2. The aggregation isn't being "recognised" so you have to manually enlist/aggregation recognised - atom automatically enlistedq)select max qty from spqty---90/aggregation not recognised - result isn't a listq)select {max x}qty from sp'rank [0] select {max x}qty from sp ^/manually enlist to ensure list outputq)select {enlist max x}qty from spqty---90Putting it all togetherq)select ?[1b;{enlist max x};{enlist min x}]qty from spqty---90q)select ?[0b;{enlist max x};{enlist min x}]qty from spqty---1

Hi 

Please try below query.

rase $[1;max;min] select qty from sp

Regards

Pankaj Kumar 

Hi 

Try below query.

raze $[0;max;min] select qty from sp