KDB从日期小于给定日期的分区表中选择-1天

时间:2019-10-02 10:54:59

标签: database date select where-clause kdb

我想从分区表中选择一个日期,该日期是严格低于给定日期d的最高日期。

我可以执行以下操作:

d:2019.10.02;
{select from x where date = max date} select from t where date < d

其中t是我的分区表。

上述查询的问题在于它非常慢,因为它必须首先加载所有严格早于d的日期,然后再将max date取出。

4 个答案:

答案 0 :(得分:3)

要选择所有早于指定日期的日期,可以使用以下select语句:

select from t where date=max date where date<d

t是您的分区表,d是您的指定日期。

答案 1 :(得分:1)

如果您只想从分区日期的hdb中的最大日期中选择

让我们假设小于2019.08.20的最大填充日期分区为2019.08.07

q)d:2019.08.20
q)select from t where date=max date where date<d

这是因为分区类型在加载到数据库后即可用作变量(例如,日期,月份,整数等)。这将是.Q.pf变量。

答案 2 :(得分:1)

select from table where date=(last .Q.pv where .Q.pv < d)

答案 3 :(得分:0)

kdb +在内存中存储一​​个变量,其中包含数据库中的所有日期。

select from telemetry where date=desc[date]1

where子句上方将按最大->最小

选择索引1会从查询中过滤出最大日期(无需先查询整个数据集)。