检查多个表中是否存在列
Check presence of a column in multiple tables
我想检查一个列是否出现在多个 table 中。
当我尝试一个 table 时,它起作用了。
`tickerCol in cols tradeTable / (output is 1b) hence working perfectly
`tickerCol in cols table2 / (output is 1b) hence working perfectly
但是当我 运行
`ticker in cols @' (tradeTable;table2) / (output is 0b, expected output 11b)
对于上面的例子,股票代码列出现在 tables(tradeTable;table2).
中
以下作品分别使用 '
:
`ticker in ' cols each (tradeTable; table2)
这将找到每个表中存在的列,然后对每个列列表执行检查以查找这些列表中是否存在 `ticker
。
解决方案已经在另一个答案中提供了。只是想解释为什么您的解决方案不起作用。
假设我们有 2 个表 t1
(列 id
和 v1
)和 t2
(列 id
和 v2
) .
现在当我们 运行:
q) cols@'`t1`t2
输出将是列表列表:
(`id`v1;`id`v2)
此列表有 2 个条目,每个条目都是一个列表。
现在您正在做的是尝试在此列表中查找列。
q) `id in (`id`v1;`id`v2) /output 0b
并且由于该列表没有 id
作为条目,因此 returns 0b
.
如果您搜索 `id`v1
这是一个列表,您将得到 1b
匹配的第一个条目。
q) `id`v1 in (`id`v1;`id`v2) / output 1b
您在这里想要的是在该列表的每个条目中搜索您的列名。所以你的表达中唯一缺少的是两者兼而有之。这将起作用:
q) `id in'cols@'`t1`t2 / output 11b
在你的情况下它将是:
q) `ticker in ' cols@'`tradeTable`table2
我想检查一个列是否出现在多个 table 中。 当我尝试一个 table 时,它起作用了。
`tickerCol in cols tradeTable / (output is 1b) hence working perfectly
`tickerCol in cols table2 / (output is 1b) hence working perfectly
但是当我 运行
`ticker in cols @' (tradeTable;table2) / (output is 0b, expected output 11b)
对于上面的例子,股票代码列出现在 tables(tradeTable;table2).
中以下作品分别使用 '
:
`ticker in ' cols each (tradeTable; table2)
这将找到每个表中存在的列,然后对每个列列表执行检查以查找这些列表中是否存在 `ticker
。
解决方案已经在另一个答案中提供了。只是想解释为什么您的解决方案不起作用。
假设我们有 2 个表 t1
(列 id
和 v1
)和 t2
(列 id
和 v2
) .
现在当我们 运行:
q) cols@'`t1`t2
输出将是列表列表:
(`id`v1;`id`v2)
此列表有 2 个条目,每个条目都是一个列表。
现在您正在做的是尝试在此列表中查找列。
q) `id in (`id`v1;`id`v2) /output 0b
并且由于该列表没有 id
作为条目,因此 returns 0b
.
如果您搜索 `id`v1
这是一个列表,您将得到 1b
匹配的第一个条目。
q) `id`v1 in (`id`v1;`id`v2) / output 1b
您在这里想要的是在该列表的每个条目中搜索您的列名。所以你的表达中唯一缺少的是两者兼而有之。这将起作用:
q) `id in'cols@'`t1`t2 / output 11b
在你的情况下它将是:
q) `ticker in ' cols@'`tradeTable`table2