如何根据另一个 table kdb 中的列从 table 中获取列

how to obtain a column from a table based on columns from another table kdb

我从 table 中查询了 3 列,如下所示:

lst: distinct select  b_market_order_no,instrumentID,mkt from tb  where event=`OvernightOrder

基于这些我想查询另一个 table 并从中获取日期列

select dates from tbp where

我不太确定如何在此处应用 where 子句或连接子句,以便 lst 中的值从 tbp 中获取相应的日期列。 tb 和 tbp tables 都有相同的列,它们是为同一模式的不同日期创建的。

如果我正确理解您的用例,那么您可以在 where 子句中使用 table,如下所示:

q)show tab1:([]a:1 2 3;b:4 5 6)
a b
---
1 4
2 5
3 6
q)show tab2:([]date:.z.d+1 2 3;a:2 3 4;b:5 6 7)
date       a b
--------------
2020.04.29 2 5
2020.04.30 3 6
2020.05.01 4 7
q)select date from tab2 where([]a;b)in tab1
date
----------
2020.04.29
2020.04.30

基本上,这会构建 tab2tab1 中的相关列的 table 并进行比较。

如果要连接的 table 的架构是可变的,则可能需要另一种方法,例如:

q)select date from tab2 where(cols[tab1]#tab2)in tab1
date
----------
2020.04.29
2020.04.30

甚至使用 lj 并添加一个额外的布尔列来标记 tab1 到 select 从 tab2:

中的有效行
select date from(tab2 lj cols[tab1]xkey update c:1b from tab1)where c