kdb select 每分钟只有一行
kdb select only one row for each minute
我在 kdb 上有一些记录,如您所见,我们有 10 行时间:"8:33"
和 19 行时间 "8:34"
以及其他一些时间行 "8:35"
。
现在,我如何才能 select 每组分钟只显示一行?
例如最终结果应该是这样的:(最终结果只应选择第二行较早的一行)
结果应该是:
9 2022-04-15 08:33:59.453 b'buy' b'ETH-USDT'
28 2022-04-15 08:34:45.511 b'sell' b'ETH-USDT'
43 2022-04-15 08:35:33.451 b'sell' b'ETH-USDT'
我的数据库:
0 2022-04-15 08:33:52.514 b'sell' b'ETH-USDT'
1 2022-04-15 08:33:56.459 b'buy' b'ETH-USDT'
2 2022-04-15 08:33:58.465 b'sell' b'ETH-USDT'
3 2022-04-15 08:33:58.847 b'sell' b'ETH-USDT'
4 2022-04-15 08:33:58.848 b'buy' b'ETH-USDT'
5 2022-04-15 08:33:58.849 b'sell' b'ETH-USDT'
6 2022-04-15 08:33:58.849 b'sell' b'ETH-USDT'
7 2022-04-15 08:33:59.262 b'sell' b'ETH-USDT'
8 2022-04-15 08:33:59.262 b'sell' b'ETH-USDT'
9 2022-04-15 08:33:59.453 b'buy' b'ETH-USDT'
10 2022-04-15 08:34:02.057 b'buy' b'ETH-USDT'
11 2022-04-15 08:34:02.387 b'sell' b'ETH-USDT'
12 2022-04-15 08:34:02.388 b'sell' b'ETH-USDT'
13 2022-04-15 08:34:03.086 b'buy' b'ETH-USDT'
14 2022-04-15 08:34:06.176 b'buy' b'ETH-USDT'
15 2022-04-15 08:34:11.061 b'buy' b'ETH-USDT'
16 2022-04-15 08:34:14.330 b'buy' b'ETH-USDT'
17 2022-04-15 08:34:15.381 b'buy' b'ETH-USDT'
18 2022-04-15 08:34:24.464 b'buy' b'ETH-USDT'
19 2022-04-15 08:34:26.146 b'sell' b'ETH-USDT'
20 2022-04-15 08:34:26.394 b'buy' b'ETH-USDT'
21 2022-04-15 08:34:26.571 b'sell' b'ETH-USDT'
22 2022-04-15 08:34:27.175 b'sell' b'ETH-USDT'
23 2022-04-15 08:34:27.654 b'buy' b'ETH-USDT'
24 2022-04-15 08:34:28.537 b'buy' b'ETH-USDT'
25 2022-04-15 08:34:30.264 b'sell' b'ETH-USDT'
26 2022-04-15 08:34:38.094 b'sell' b'ETH-USDT'
27 2022-04-15 08:34:41.202 b'sell' b'ETH-USDT'
28 2022-04-15 08:34:45.511 b'sell' b'ETH-USDT'
29 2022-04-15 08:35:02.625 b'buy' b'ETH-USDT'
30 2022-04-15 08:35:04.008 b'buy' b'ETH-USDT'
31 2022-04-15 08:35:06.377 b'sell' b'ETH-USDT'
32 2022-04-15 08:35:23.843 b'sell' b'ETH-USDT'
33 2022-04-15 08:35:23.845 b'sell' b'ETH-USDT'
34 2022-04-15 08:35:23.845 b'sell' b'ETH-USDT'
35 2022-04-15 08:35:23.845 b'sell' b'ETH-USDT'
36 2022-04-15 08:35:23.845 b'sell' b'ETH-USDT'
37 2022-04-15 08:35:23.845 b'sell' b'ETH-USDT'
38 2022-04-15 08:35:26.986 b'sell' b'ETH-USDT'
39 2022-04-15 08:35:31.219 b'buy' b'ETH-USDT'
40 2022-04-15 08:35:31.221 b'buy' b'ETH-USDT'
41 2022-04-15 08:35:31.897 b'buy' b'ETH-USDT'
42 2022-04-15 08:35:31.898 b'sell' b'ETH-USDT'
43 2022-04-15 08:35:33.451 b'sell' b'ETH-USDT'
您可以使用:
value select by b.minute from t
其中 b
是您的时间戳列,t
是您的 table。
示例:
q)show t:([]a:til 10; b:.z.p-00:04 00:04 00:04 00:03 00:03 00:03 00:01 00:00 00:00 00:00; c:10?`3 )
a b c
-----------------------------------
0 2022.04.15D09:09:11.100787000 ndd
1 2022.04.15D09:09:11.100787000 hpb
2 2022.04.15D09:09:11.100787000 ihm
3 2022.04.15D09:10:11.100787000 fph
4 2022.04.15D09:10:11.100787000 gmg
5 2022.04.15D09:10:11.100787000 kpf
6 2022.04.15D09:12:11.100787000 ecp
7 2022.04.15D09:13:11.100787000 mai
8 2022.04.15D09:13:11.100787000 bof
9 2022.04.15D09:13:11.100787000 mno
q)select by b.minute from t
minute| a b c
------| -----------------------------------
09:09 | 2 2022.04.15D09:09:11.100787000 ihm
09:10 | 5 2022.04.15D09:10:11.100787000 kpf
09:12 | 6 2022.04.15D09:12:11.100787000 ecp
09:13 | 9 2022.04.15D09:13:11.100787000 mno
q)value select by b.minute from t
a b c
-----------------------------------
2 2022.04.15D09:09:11.100787000 ihm
5 2022.04.15D09:10:11.100787000 kpf
6 2022.04.15D09:12:11.100787000 ecp
9 2022.04.15D09:13:11.100787000 mno
我在 kdb 上有一些记录,如您所见,我们有 10 行时间:"8:33"
和 19 行时间 "8:34"
以及其他一些时间行 "8:35"
。
现在,我如何才能 select 每组分钟只显示一行? 例如最终结果应该是这样的:(最终结果只应选择第二行较早的一行)
结果应该是:
9 2022-04-15 08:33:59.453 b'buy' b'ETH-USDT'
28 2022-04-15 08:34:45.511 b'sell' b'ETH-USDT'
43 2022-04-15 08:35:33.451 b'sell' b'ETH-USDT'
我的数据库:
0 2022-04-15 08:33:52.514 b'sell' b'ETH-USDT'
1 2022-04-15 08:33:56.459 b'buy' b'ETH-USDT'
2 2022-04-15 08:33:58.465 b'sell' b'ETH-USDT'
3 2022-04-15 08:33:58.847 b'sell' b'ETH-USDT'
4 2022-04-15 08:33:58.848 b'buy' b'ETH-USDT'
5 2022-04-15 08:33:58.849 b'sell' b'ETH-USDT'
6 2022-04-15 08:33:58.849 b'sell' b'ETH-USDT'
7 2022-04-15 08:33:59.262 b'sell' b'ETH-USDT'
8 2022-04-15 08:33:59.262 b'sell' b'ETH-USDT'
9 2022-04-15 08:33:59.453 b'buy' b'ETH-USDT'
10 2022-04-15 08:34:02.057 b'buy' b'ETH-USDT'
11 2022-04-15 08:34:02.387 b'sell' b'ETH-USDT'
12 2022-04-15 08:34:02.388 b'sell' b'ETH-USDT'
13 2022-04-15 08:34:03.086 b'buy' b'ETH-USDT'
14 2022-04-15 08:34:06.176 b'buy' b'ETH-USDT'
15 2022-04-15 08:34:11.061 b'buy' b'ETH-USDT'
16 2022-04-15 08:34:14.330 b'buy' b'ETH-USDT'
17 2022-04-15 08:34:15.381 b'buy' b'ETH-USDT'
18 2022-04-15 08:34:24.464 b'buy' b'ETH-USDT'
19 2022-04-15 08:34:26.146 b'sell' b'ETH-USDT'
20 2022-04-15 08:34:26.394 b'buy' b'ETH-USDT'
21 2022-04-15 08:34:26.571 b'sell' b'ETH-USDT'
22 2022-04-15 08:34:27.175 b'sell' b'ETH-USDT'
23 2022-04-15 08:34:27.654 b'buy' b'ETH-USDT'
24 2022-04-15 08:34:28.537 b'buy' b'ETH-USDT'
25 2022-04-15 08:34:30.264 b'sell' b'ETH-USDT'
26 2022-04-15 08:34:38.094 b'sell' b'ETH-USDT'
27 2022-04-15 08:34:41.202 b'sell' b'ETH-USDT'
28 2022-04-15 08:34:45.511 b'sell' b'ETH-USDT'
29 2022-04-15 08:35:02.625 b'buy' b'ETH-USDT'
30 2022-04-15 08:35:04.008 b'buy' b'ETH-USDT'
31 2022-04-15 08:35:06.377 b'sell' b'ETH-USDT'
32 2022-04-15 08:35:23.843 b'sell' b'ETH-USDT'
33 2022-04-15 08:35:23.845 b'sell' b'ETH-USDT'
34 2022-04-15 08:35:23.845 b'sell' b'ETH-USDT'
35 2022-04-15 08:35:23.845 b'sell' b'ETH-USDT'
36 2022-04-15 08:35:23.845 b'sell' b'ETH-USDT'
37 2022-04-15 08:35:23.845 b'sell' b'ETH-USDT'
38 2022-04-15 08:35:26.986 b'sell' b'ETH-USDT'
39 2022-04-15 08:35:31.219 b'buy' b'ETH-USDT'
40 2022-04-15 08:35:31.221 b'buy' b'ETH-USDT'
41 2022-04-15 08:35:31.897 b'buy' b'ETH-USDT'
42 2022-04-15 08:35:31.898 b'sell' b'ETH-USDT'
43 2022-04-15 08:35:33.451 b'sell' b'ETH-USDT'
您可以使用:
value select by b.minute from t
其中 b
是您的时间戳列,t
是您的 table。
示例:
q)show t:([]a:til 10; b:.z.p-00:04 00:04 00:04 00:03 00:03 00:03 00:01 00:00 00:00 00:00; c:10?`3 )
a b c
-----------------------------------
0 2022.04.15D09:09:11.100787000 ndd
1 2022.04.15D09:09:11.100787000 hpb
2 2022.04.15D09:09:11.100787000 ihm
3 2022.04.15D09:10:11.100787000 fph
4 2022.04.15D09:10:11.100787000 gmg
5 2022.04.15D09:10:11.100787000 kpf
6 2022.04.15D09:12:11.100787000 ecp
7 2022.04.15D09:13:11.100787000 mai
8 2022.04.15D09:13:11.100787000 bof
9 2022.04.15D09:13:11.100787000 mno
q)select by b.minute from t
minute| a b c
------| -----------------------------------
09:09 | 2 2022.04.15D09:09:11.100787000 ihm
09:10 | 5 2022.04.15D09:10:11.100787000 kpf
09:12 | 6 2022.04.15D09:12:11.100787000 ecp
09:13 | 9 2022.04.15D09:13:11.100787000 mno
q)value select by b.minute from t
a b c
-----------------------------------
2 2022.04.15D09:09:11.100787000 ihm
5 2022.04.15D09:10:11.100787000 kpf
6 2022.04.15D09:12:11.100787000 ecp
9 2022.04.15D09:13:11.100787000 mno