gpt4 book ai didi

kdb - 使用like搜索多个字符串

转载 作者:行者123 更新时间:2023-12-01 10:21:56 24 4
gpt4 key购买 nike

使用方法 like用于搜索多个字符串?

q)\l sp.q

q)select from p where city like "lon*"
p | name color weight city
--| -------------------------
p1| nut red 12 london
p4| screw red 14 london
p6| cog red 19 london

我要搜索 city以“lon”或“par”开头, /:type错误。
q)select from p where city like/: ("lon*";"par*")
'type

最佳答案

您需要使用 any搜索多个字符串时。

q)select from p where any city like/: ("lon*";"par*")

p | name color weight city
--| -------------------------
p1| nut red 12 london
p2| bolt green 17 paris
p4| screw red 14 london
p5| cam blue 12 paris
p6| cog red 19 london

当您使用 /: 进行搜索时(每个都正确),它返回 2 个向量,一个针对“lon*”搜索,另一个针对“par*”。
(0!p)[`city] like/: ("lon*";"par*")
(100101b;010010b)

使用 any执行 ORing 并返回单个向量。
any (0!p)[`city] like/: ("lon*";"par*")
110111b

现在得到最终结果:
(0!p) where any (0!p)[`city] like/: ("lon*";"par*")
p name color weight city
----------------------------
p1 nut red 12 london
p2 bolt green 17 paris
p4 screw red 14 london
p5 cam blue 12 paris
p6 cog red 19 london

关于kdb - 使用like搜索多个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50357373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com