我有下表,我试图在每组diffFlag存储桶中获取第一个和最后一个eventTime之间的差值
t:flip (`orderID`sym`eventTimes`side`diffFlag)!(190710 190973 191017 191124 191286 191294 191297 191298 191348 191404;`EURUSD`EURUSD`EURUSD`EURUSD`EURUSD`EURUSD`EURUSD`EURUSD`EURUSD`EURUSD;(02:08:22.674 02:09:05.930;02:18:00.140 02:18:00.140;02:19:31.614 02:24:21.263;02:24:32.710 02:25:26.757;02:30:21.386 02:30:21.386;02:30:36.206 02:30:36.206;02:30:37.607 02:30:37.607;02:30:39.070 02:30:39.070;02:32:06.494 02:34:45.977;02:34:49.426 02:34:49.426);"BSBBSSSSBB";1 2 3 3 4 4 4 4 5 5)
我了解到以下更新语句,但是它未正确汇总。每当diffFlag计数> 1
时,timeDiff应该重置 update sums timeDiff by diffFlag from update timeDiff:(first eventTimes)-last eventTimes by diffFlag from t
任何帮助将不胜感激!
谢谢
答案 0 :(得分:0)
q)select {last[x] - first[x]}[last eventTimes] by diffFlag from t
diffFlag| eventTimes
--------| ------------
1 | 00:00:43.256
2 | 00:00:00.000
3 | 00:00:54.047
4 | 00:00:00.000
5 | 00:00:00.000
更新原始表:
q)update timeDiff:{last[x] - first[x]}[last eventTimes] by diffFlag from t
orderID sym eventTimes side diffFlag timeDiff
-------------------------------------------------------------------
190710 EURUSD 02:08:22.674 02:09:05.930 B 1 00:00:43.256
190973 EURUSD 02:18:00.140 02:18:00.140 S 2 00:00:00.000
191017 EURUSD 02:19:31.614 02:24:21.263 B 3 00:00:54.047
191124 EURUSD 02:24:32.710 02:25:26.757 B 3 00:00:54.047
191286 EURUSD 02:30:21.386 02:30:21.386 S 4 00:00:00.000
191294 EURUSD 02:30:36.206 02:30:36.206 S 4 00:00:00.000
191297 EURUSD 02:30:37.607 02:30:37.607 S 4 00:00:00.000
191298 EURUSD 02:30:39.070 02:30:39.070 S 4 00:00:00.000
191348 EURUSD 02:32:06.494 02:34:45.977 B 5 00:00:00.000
191404 EURUSD 02:34:49.426 02:34:49.426 B 5 00:00:00.000