KDB+:将 2 阶段查询转换为单阶段查询的有效方法?
KDB+:Efficient method of converting a 2 stage query into a one stage query?
我想将以下查询转换为单个查询
tab:([price:til 10]side:10?-1 1;qty:990 + 2 * til 10);
a:select[>price] from tab where side=1;
b:select from a where sums[qty] <= max(min[sums qty];100);
或
select from (select[>price] from tab where side=1) where sums[qty] <= max(min[sums qty];100);
我尝试使用 fby 实现 select 语句,如下所示:
select from tab where side=-1, ({sy:sums[y]; sy<=max(min[sy];x)}[100];qty) fby side
然而,这并没有正确排序 table tab
,即根据 >price
。
我想可以预先对 table 进行排序,即
select from `price xasc tab ...
然而,这似乎是一个计算效率低下的解决方案。请一些聪明的问神告诉我如何最有效地实现这一目标。
谢谢,最好的问候
如果table需要按价格降序排列sums qty
计算,则使用xdesc
或desc
似乎是不可避免的一步。
这是我能找到的最简洁的查询版本。
select from desc tab where side=1,sums[qty]<=max(min sums qty;100)
我很难理解你为什么要这样计算。排序会产生影响,因为它会影响在数量随着总和逐渐变大之前哪个值是第一个。你有没有使用这样的东西的原因:
q)select from tab where qty = max qty
price| side qty
-----| ---------
9 | 1 1008
q)select from tab where qty = (max;qty) fby side
price| side qty
-----| ---------
8 | -1 1006
9 | 1 1008
我想将以下查询转换为单个查询
tab:([price:til 10]side:10?-1 1;qty:990 + 2 * til 10);
a:select[>price] from tab where side=1;
b:select from a where sums[qty] <= max(min[sums qty];100);
或
select from (select[>price] from tab where side=1) where sums[qty] <= max(min[sums qty];100);
我尝试使用 fby 实现 select 语句,如下所示:
select from tab where side=-1, ({sy:sums[y]; sy<=max(min[sy];x)}[100];qty) fby side
然而,这并没有正确排序 table tab
,即根据 >price
。
我想可以预先对 table 进行排序,即
select from `price xasc tab ...
然而,这似乎是一个计算效率低下的解决方案。请一些聪明的问神告诉我如何最有效地实现这一目标。 谢谢,最好的问候
如果table需要按价格降序排列sums qty
计算,则使用xdesc
或desc
似乎是不可避免的一步。
这是我能找到的最简洁的查询版本。
select from desc tab where side=1,sums[qty]<=max(min sums qty;100)
我很难理解你为什么要这样计算。排序会产生影响,因为它会影响在数量随着总和逐渐变大之前哪个值是第一个。你有没有使用这样的东西的原因:
q)select from tab where qty = max qty
price| side qty
-----| ---------
9 | 1 1008
q)select from tab where qty = (max;qty) fby side
price| side qty
-----| ---------
8 | -1 1006
9 | 1 1008