KDB+ 中列表的所有子集

格里

我是 KDB 的新手。我有以下格式的表格:

id        date  name  order
34  2020.01.20  John     10
23  2020.01.20  John    -20
21  2020.01.20  John     30
43  2020.01.20  John   -400
44  2020.01.20   Dan  -6483  
22  2020.01.20   Dan   8796

可以按如下方式创建示例表:

t:([]id:(34, 23, 21, 43, 44, 22); date:(2020.01.20; 2020.01.20; 2020.01.20; 2020.01.20; 2020.01.20; 2020.01.20); name:(`John`John`John`John`Dan`Dan); order:(10, -20, 30, -400, -6483, 8796));

我想要任何给定datename以下格式的所有订单子集现在,order下面列的总和order的价值id和所有ids

id        date  name  order    ids
34  2020.01.20  John     10     0n
34  2020.01.20  John    -10     23
34  2020.01.20  John     40     21
34  2020.01.20  John   -390     43
34  2020.01.20  John     20     23, 21
34  2020.01.20  John   -360     21, 43
34  2020.01.20  John   -380     23, 21, 43
23  2020.01.20  John    -20     0n
23  2020.01.20  John    -10     34
23  2020.01.20  John     10     21
23  2020.01.20  John   -420     43
23  2020.01.20  John     20     34, 21
23  2020.01.20  John   -390     21, 43
23  2020.01.20  John   -380     34, 21, 43
21  2020.01.20  John     30     0n
21  2020.01.20  John     40     34
21  2020.01.20  John     10     23
21  2020.01.20  John   -370     43
21  2020.01.20  John     20     34, 23
21  2020.01.20  John     20     23, 43
21  2020.01.20  John   -380     34, 23, 43
43  2020.01.20  John   -400     0n
43  2020.01.20  John   -390     34
43  2020.01.20  John   -420     23
43  2020.01.20  John   -370     21
43  2020.01.20  John   -410     34, 23
43  2020.01.20  John   -390     23, 21
43  2020.01.20  John   -380     34, 23, 21
44  2020.01.20   Dan  -6483     0n
44  2020.01.20   Dan   2313     22
22  2020.01.20   Dan   8796     0n
22  2020.01.20   Dan   2313     44
特里林奇

这让你有一部分方法,尽管这种方法有一个你似乎排除的额外组合(如果需要,你可以在之后排除这些):

q)comb:{$[type b:(count[a:x except y]-1)(01b cross)/01b;(`long$();a);a where each b]};
q)update sum each order from ungroup ungroup select id,order:(order,/:'order i?comb[i]each i),ids:id i?comb[i]each i by date,name from t
date       name id order ids
---------------------------------
2020.01.20 Dan  44 -6483 `long$()
2020.01.20 Dan  44 2313  ,22
2020.01.20 Dan  22 8796  `long$()
2020.01.20 Dan  22 2313  ,44
2020.01.20 John 34 10    `long$()
2020.01.20 John 34 -390  ,43
2020.01.20 John 34 40    ,21
2020.01.20 John 34 -360  21 43
2020.01.20 John 34 -10   ,23
2020.01.20 John 34 -410  23 43
2020.01.20 John 34 20    23 21
2020.01.20 John 34 -380  23 21 43
2020.01.20 John 23 -20   `long$()
2020.01.20 John 23 -420  ,43
...

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章