如何查询KDB table 其中一列是列表?

How to query KDB table where one column is a list?

我在 KDB 中有一个 table,其中一列是符号列表,例如:-

q)table:([id:1 2 3 4 5] books:((`book1`book2);(enlist `book6);(enlist`book3);(enlist`book4);(`book2;`book5)))
q)table
id| books
--| ------------
1 | `book1`book2
2 | ,`book6
3 | ,`book3
4 | ,`book4
5 | `book2`book5
q)

我想找到 `book2 是 books 列中其中一本书的所有行,我该怎么做?所以在上面的示例中,我希望返回第 1 行和第 5 行。我使用 "in" 运算符尝试过各种操作,但要么出现错误,要么没有结果,例如 :-

q)select from books where `book2 in books
clientTradeId| book
-------------| ----
q)select from books where enlist `books2 in books
'length
select from table where `book2 in'books

这利用了副词 each-both,请在此处阅读更多相关信息: http://code.kx.com/q4m3/6_Functions/#672-each-both

select from table where `book2 in/:books

有效,使用 eachright 副词。

另一个有用的变体,您希望将 any/all 的输入书籍匹配到 books 列:

1) 这将 return 同时具有 book2book5 的行(使用 all each):

q)select from table where  all each `book2`book5 in/:books
id| books
--| -----------
5 | book2 book5

2) 这将 return 具有 book2book4 的行(使用 any each

q)select from table where  any each `book4`book5 in/:books
id| books
--| ------------
4 | ,`book4
5 | `book2`book5