首先,列是布尔向量,这样你就可以在where
子句中使用“原始”:
q)tbl
red blue green yellow white purple
----------------------------------
0 0 1 0 0 0
1 0 1 1 0 0
1 0 1 1 1 0
0 0 0 0 0 0
0 1 0 0 1 1
1 0 1 1 0 0
q)select from tbl where red or green
red blue green yellow white purple
----------------------------------
0 0 1 0 0 0
1 0 1 1 0 0
1 0 1 1 1 0
1 0 1 1 0 0
您可以使用自己的函数中where
子句?绝对。
q)isRG:{or/[x`red`green]}
q)isRG tbl
111001b
q)select from tbl where isRG tbl
red blue green yellow white purple
----------------------------------
0 0 1 0 0 0
1 0 1 1 0 0
1 0 1 1 1 0
1 0 1 1 0 0
去超越你的问题,使列名参数的功能,而不是写在Q-SQL where
子句中使用函数,使用functional select。在这里,你将你的约束表达为parse tree,例如, (or;`red;`white)
q)?[tbl; enlist(or; `red; `white); 0b;()]
red blue green yellow white purple
----------------------------------
1 0 1 1 0 0
1 0 1 1 1 0
0 1 0 0 1 1
1 0 1 1 0 0
然后,您可以参数化的列名:
q)selEither:{[t; c1; c2] ?[t; enlist(or; c1 ;c2); 0b;()]}
q)selEither[tbl; `red; `white]
red blue green yellow white purple
----------------------------------
1 0 1 1 0 0
1 0 1 1 1 0
0 1 0 0 1 1
1 0 1 1 0 0
最后,您可以从一对延长这一列名的列表:
q)selAny:{[tbl; cn] ?[tbl; enlist(or/;enlist,cn); 0b;()]}
q)selAny[t; `white`green`yellow]
…
查看更多在KX技术白皮书Parse Trees and Functional Forms
来源
2017-09-14 18:34:51
SJT
J确保评估布尔值或布尔值列表的权利。 – Chromozorz