我有下表t:
t:([]sym:3#`ibm;time:10:01:01 10:01:04 10:01:08;price:100 101 105;val:("hello";"world";"test"))
Run Code Online (Sandbox Code Playgroud)
如何执行以下查询:
select from t where val in ("hello"; "test")
Run Code Online (Sandbox Code Playgroud)
其中我期待以下结果:
sym time price val
---------------------------
ibm 10:01:01 100 hello
ibm 10:01:08 105 test
Run Code Online (Sandbox Code Playgroud)
小智 6
看起来您的查询确实返回了您需要的结果.
或者,可以使用关键字"like".
当我们在select语句的末尾使用where子句时,'where'部分需要一个布尔值来告诉它是否应该选择该列.
当我们这样做时where val in "hello",它实际上会为它匹配的字符串的每个元素返回一个布尔值(当它没有被包装时):
q)val:"hello"
q)val in "hello"
11111b
Run Code Online (Sandbox Code Playgroud)
因此,要获得返回的单个布尔值,我们使用关键字 like
q)val like "hello"
1b
Run Code Online (Sandbox Code Playgroud)
此外,在将字符串列表传递给where子句时,应使用'each-right'副词来指示where子句对列表的每个实例进行操作.
q)val like/: ("hello";"test")
10b
Run Code Online (Sandbox Code Playgroud)
然而,当where子句期望单个时,我们再次遇到多个布尔值
因此,any当存在hello或test时, 我们使用关键字返回结果.
q)any val like/: ("hello";"test")
1b
Run Code Online (Sandbox Code Playgroud)
我们可以看到,这给出了所需的结果
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"
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
171 次 |
| 最近记录: |