KDB,比较两个不同系统在时间段内产生的值

KDB,比较两个不同系统在时间段内产生的值,kdb,q-lang,Kdb,Q Lang,我有两个不同的系统将数据推送到kdb表中。这些都是由价格推动的。 我想比较生成的值,以便最终标记较大的差异。 不过,我对kdb非常陌生,甚至很难找到一个起始点查询 最后,我想花一个时间段(可能是一分钟),在这个时间段内为每个系统找到一行,其中驱动价格相同,并比较导出的值 不过,对我来说,一个很好的起点是了解如何在一个时间段内获取每个系统的第一行并进行比较/加入 谢谢 简化示例数据 例如:- System | Time | driver | result1 | res

我有两个不同的系统将数据推送到kdb表中。这些都是由价格推动的。 我想比较生成的值,以便最终标记较大的差异。 不过,我对kdb非常陌生,甚至很难找到一个起始点查询

最后,我想花一个时间段(可能是一分钟),在这个时间段内为每个系统找到一行,其中驱动价格相同,并比较导出的值

不过,对我来说,一个很好的起点是了解如何在一个时间段内获取每个系统的第一行并进行比较/加入

谢谢

简化示例数据

例如:-

System             | Time    | driver | result1 | result2
systemA.instrument1| 11:59:59| 101.4  | 3.4     | 4.6
systemA.instrument1| 12:00:01| 101.5  | 3.8     | 4.8
systemA.instrument1| 12:00:02| 101.6  | 3.3     | 2.3
systemA.instrument2| 12:00:02| 106.6  | 11.1    | 11.3
systemA.instrument1| 12:00:05| 101.7  | 3.9     | 5.6
systemB.instrument1| 12:00:09| 101.1  | 3.2     | 7.8
systemB.instrument1| 12:00:14| 101.2  | 3.9     | 3.4
systemB.instrument1| 12:00:17| 101.3  | 3.1     | 8.9
systemB.instrument2| 12:00:19| 106.5  | 11.2    | 11.4
systemB.instrument1| 12:00:58| 101.7  | 3.9     | 9.3
systemB.instrument1| 12:00:59| 101.7  | 3.3     | 3.4
systemB.instrument1| 12:01:03| 101.4  | 3.1     | 5.6
我只需要12:00:00-12:00:59的数据

SystemA和SystemB instrument1之间唯一匹配的驱动程序是101.7。我希望使用其中一个,并显示结果之间的差异。 对于仪表2,驱动程序从不匹配,因此我希望使用系统之间最接近的驱动程序价格

results      | driver | driver diff | result1diff | result2diff
instrument1  | 101.7  | 0           | 0           | 3.7
instrument2  |        | 0.1         | 0.1         | 0.1

首先,将系统列拆分为其组成部分:

table:(flip exec `System`Instrument!flip ` vs/: System from table)
    ,'delete System from table
您的第一个问题(每个仪器和系统的第一行)的答案是:

顺便说一句,在q中,请求最后一行是更常见的用例,这更容易实现:

q)select by Instrument,System from table
定义函数以查找两个数值向量中最接近值的索引:

q)closest:{a:a?min a:abs(-) ./: x cross y;(a div count y;a mod count y)}
最接近驱动程序的查询结果1:

q)select result1:result1(value group System)@'closest . value driver group System by Instrument from table

Instrument | result1  
-----------| ---------
instrument1| 3.4  3.1 
instrument2| 11.1 11.2

您能否提供当前数据、格式和预期输出的具体示例?
q)select result1:result1(value group System)@'closest . value driver group System by Instrument from table

Instrument | result1  
-----------| ---------
instrument1| 3.4  3.1 
instrument2| 11.1 11.2