2022.04.08 09:50 PM
suppose i have a table with filed1 is list of symbol `1m`3m and filed2 is source `bbg`bbg
then how should i read
1. #[;1b] each count each field2 from table
2. {x 1 0} each filed1 from table
2022.04.09 05:01 AM
count each field2
implies each item of field2
is a list – its length to be counted{x 1 0}
specifies the second and first items of a list, implying field1
is also nested
q)show t:([]field1:(2+5?3)?\:`$string[til 10],'"m";field2:(1+5?5)?\:5?`3)
field1 field2
------------------------------
`9m`1m `dmp`gce`gdp
`4m`3m`9m `gce`dmp`dmp`nmo`gdp
`8m`9m ,`icg
`9m`5m`4m `icg`gce`nmo`nmo`gce
`0m`4m`3m `dmp`icg`icg`gce
q)select {x 1 0}each field1, #[;1b] each count each field2 from t
field1 field2
-------------
1m 9m 111b
3m 4m 11111b
9m 8m ,1b
5m 9m 11111b
4m 0m 1111b
Above:
field1
field2
listsAlternative expression:
q)select reverse each 2#'field1, not null field2 from t
field1 field2
-------------
1m 9m 111b
3m 4m 11111b
9m 8m ,1b
5m 9m 11111b
4m 0m 1111b
2022.04.09 05:01 AM
count each field2
implies each item of field2
is a list – its length to be counted{x 1 0}
specifies the second and first items of a list, implying field1
is also nested
q)show t:([]field1:(2+5?3)?\:`$string[til 10],'"m";field2:(1+5?5)?\:5?`3)
field1 field2
------------------------------
`9m`1m `dmp`gce`gdp
`4m`3m`9m `gce`dmp`dmp`nmo`gdp
`8m`9m ,`icg
`9m`5m`4m `icg`gce`nmo`nmo`gce
`0m`4m`3m `dmp`icg`icg`gce
q)select {x 1 0}each field1, #[;1b] each count each field2 from t
field1 field2
-------------
1m 9m 111b
3m 4m 11111b
9m 8m ,1b
5m 9m 11111b
4m 0m 1111b
Above:
field1
field2
listsAlternative expression:
q)select reverse each 2#'field1, not null field2 from t
field1 field2
-------------
1m 9m 111b
3m 4m 11111b
9m 8m ,1b
5m 9m 11111b
4m 0m 1111b
2022.04.09 06:38 AM
thanks for the reply what does #[;1b] mean
2022.04.11 01:51 AM
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.