Functional select with fby, grouping on multiple columns

1,196 views
Skip to first unread message

Al

unread,
Jun 13, 2017, 4:50:19 PM6/13/17
to Kdb+ Personal Developers
Hi KDB gurus,

I've figured out that the functional form of this query: 

select from rows where 1=(count;i) fby ([]sym;market;id;price;size;eventType)

is this:

?[rows;enlist(=;1;(fby;(enlist;#:;`i);(+:;(!;enlist`sym`market`id`price`size`eventType;(enlist;`sym;`market;`id;`price;`size;`eventType)))));0b;()]

My question is how can I run the functional select if the grouped columns are passed in/stored in a variable? I have `sym`market`id`price`size`eventType passed into a function and stored in a variable gCols, but am having trouble trying to correctly place that in the functional select in the fby section. Thanks

Al

unread,
Jun 13, 2017, 4:50:20 PM6/13/17
to Kdb+ Personal Developers
Hi KDB Gurus,

I have the functional form of this query:

select from rows where 1=(count;i) fby ([]sym;market;id;price;size;eventType)

as:

?[rows;enlist(=;1;(fby;(enlist;#:;`i);(+:;(!;enlist`sym`market`id`price`size`eventType;(enlist;`sym;`market;`id;`price;`size;`eventType)))));0b;()]

I have my symbol list of columns I want to group on, `sym`market`id`price`size`eventType, stored in a local variable gCols. I am not sure how to run the functional form using my local variable. Help is much appreciated. Thanks.

Ajay

unread,
Jun 13, 2017, 5:32:34 PM6/13/17
to Kdb+ Personal Developers
try something like this (assuming rows is available in scope)


{[gCols]
   
?[rows;enlist(=;1;(fby;(enlist;count;`i);(flip;(!;enlist gCols;(enlist,gCols)))));0b;()]
}[`
sym`market`id`price`size`eventType]
Reply all
Reply to author
Forward
0 new messages