使用 where 子句从 KDB table 计数
Count from KDB table with where clause
我知道计数 table 告诉您 table 中有多少行,但是您如何从 table 中使用 where 子句作为过滤器进行计数?我尝试计数 table where PERIOD=x 但我收到错误:'PERIOD 即使 PERIOD 是 table
中的一个字段
使用qsql筛选然后统计结果:
count select from table where PERIOD=x
如果只需要计数,
exec sum PERIOD=x from table
如果 table 有很多列,这会比
快得多
count select from table where PERIOD=x
请注意,这会将布尔值的总和计算为 32 位整数,因此如果您的 table 有超过十亿行,您可能需要添加一个转换:
exec sum "j"$PERIOD=x from table
以下将是最有效的。
select count i from table where PERIOD=x
@jomahony 解决方案将要求在进行计数之前从磁盘读取所有列(如果 table 在磁盘上),因此效率低下
我知道计数 table 告诉您 table 中有多少行,但是您如何从 table 中使用 where 子句作为过滤器进行计数?我尝试计数 table where PERIOD=x 但我收到错误:'PERIOD 即使 PERIOD 是 table
中的一个字段使用qsql筛选然后统计结果:
count select from table where PERIOD=x
如果只需要计数,
exec sum PERIOD=x from table
如果 table 有很多列,这会比
快得多count select from table where PERIOD=x
请注意,这会将布尔值的总和计算为 32 位整数,因此如果您的 table 有超过十亿行,您可能需要添加一个转换:
exec sum "j"$PERIOD=x from table
以下将是最有效的。
select count i from table where PERIOD=x
@jomahony 解决方案将要求在进行计数之前从磁盘读取所有列(如果 table 在磁盘上),因此效率低下