来自分区 table 的 KDB Select,其中日期小于给定日期 - 1 天
KDB Select from partitioned table where date is less than a given date - 1 day
我想 select 来自分区 table 的日期是严格低于给定日期 d
.
的最高日期
我可以做到以下几点:
d:2019.10.02;
{select from x where date = max date} select from t where date < d
其中 t
是我的分区 table。
上述查询的问题在于它非常慢,因为它必须首先加载严格早于 d
的所有日期,然后从中取出 max date
。
如果您只是想select 从日期分区 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
变量。
kdb+ 在内存中存储一个变量,其中包含数据库中的所有日期。
select from telemetry where date=desc[date]1
上面的 where 子句将按最大 -> 最小排序
选择索引 1 将从您的查询中过滤出最大日期(无需先查询整个数据集)。
要select所有早于您指定日期的日期,您可以使用下面的select语句:
select from t where date=max date where date<d
其中 t
是您的分区 table,d
是您指定的日期。
select from table where date=(last .Q.pv where .Q.pv < d)
我想 select 来自分区 table 的日期是严格低于给定日期 d
.
我可以做到以下几点:
d:2019.10.02;
{select from x where date = max date} select from t where date < d
其中 t
是我的分区 table。
上述查询的问题在于它非常慢,因为它必须首先加载严格早于 d
的所有日期,然后从中取出 max date
。
如果您只是想select 从日期分区 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
变量。
kdb+ 在内存中存储一个变量,其中包含数据库中的所有日期。
select from telemetry where date=desc[date]1
上面的 where 子句将按最大 -> 最小排序
选择索引 1 将从您的查询中过滤出最大日期(无需先查询整个数据集)。
要select所有早于您指定日期的日期,您可以使用下面的select语句:
select from t where date=max date where date<d
其中 t
是您的分区 table,d
是您指定的日期。
select from table where date=(last .Q.pv where .Q.pv < d)