K code in functional query 2

https://learninghub.kx.com/forums/topic/k-code-in-functional-query-2

  1. Give functional form for:

    select sum size by ticker:((string[id],:"."),'string[ex])from trade_usq where any not null(size;price)

  2. After doing 

    parse"select sum size by ticker:((string[id],'\".\"),'string[ex])from trade_usq where any not null(size;price)"

    I get;

    ?
    `trade_usq
    ,,(max$["b"];(~:;(^:;(enlist;`size;`price))))
    (,`ticker)!,((';,);((';,);($:;`id);".");($:;`ex))
    (,`size)!,(sum;`size)

    I have then wrote out;

    ?[`trade_usq;enlist(max$["b"];(~:;(^:;(enlist;`size;`price))));(enlist`ticker)!enlist((';enlist);((';enlist);($:;`id);".");($:;`ex));(enlist`size)!enlist(sum;`size)]

    But this doesn't seem to work? What is wrong with this?

Note that you never need to use `each` with `string`. `string` already implicitly expands over lists.

When using `parse` on a q expression, any functions in the `.q` namespace are replaced by their definition. You can type `.q` at the prompt to see these definitions, and if you work in q enough, you will learn to recognize them.

`k){x/:y}` stands for `sv`

`k){x'y}` stands for `each`, which is redundant as mentioned above

So the full query would look like

```

![t;();0b;enlist[`ric]!enlist(`$;("."sv/:;(string;(flip;(enlist;`sym;`exch)))))]

```

[Reposting answer above as plain text for readability]
Note that you never need to use each with string. string already implicitly expands over lists.

When using parse on a q expression, any functions in the .q namespace are replaced by their definition. You can type .q at the prompt to see these definitions, and if you work in q enough, you will learn to recognize them.

k){x/:y} stands for sv

k){x'y} stands for each, which is redundant as mentioned above

So the full query would look like

![t;();0b;enlist[`ric]!enlist(`$;("."sv/:;(string;(flip;(enlist;`sym;`exch)))))]