KDB:如何使用列表搜索 table

KDB: how to search a table with a list

我有以下 table t:

t:([]sym:3#`ibm;time:10:01:01 10:01:04 10:01:08;price:100 101 105;val:("hello";"world";"test"))

如何执行以下查询:

select from t where val in ("hello"; "test")

其中我期待以下结果:

sym time        price val
---------------------------
ibm 10:01:01    100   hello
ibm 10:01:08    105   test
 q) select from t where any val like/: ("hello"; "test")

输出:

sym time        price val
---------------------------
ibm 10:01:01    100   hello
ibm 10:01:08    105   test

您的查询看起来 return 您需要的结果。

或者,可以使用关键字 'like'。

当我们在 select 语句末尾使用 where 子句时,'where' 部分需要一个布尔值来告诉它该列是否应该 selected。

当我们执行 where val in "hello" 时,它实际上 return 一个布尔值 它匹配的字符串 的每个元素(当它不是包裹):

q)val:"hello"
q)val in "hello"
11111b

因此,要获得单个布尔值 returned,我们使用关键字 like

q)val like "hello"
1b

此外,将字符串列表传递给where子句时,应使用'each-right'副词来指示where子句对每个实例进行操作列表。

q)val like/: ("hello";"test")
10b

但是,当 where 子句需要单个

时,我们再次面临多个布尔值

因此,当 either hello 或 [=38= 时,我们使用关键字 any 来 return 结果]测试存在。

q)any val like/: ("hello";"test")
1b

我们可以看到,这给出了所需的结果

q)select from t where any val like/: ("hello";"test")
sym time     price val
--------------------------
ibm 10:01:01 100   "hello"
ibm 10:01:08 105   "test"

希望对您有所帮助