使用每个 kdb 从另一个 table 中的列表中找到不同的值

find distinct values from a list in another table using each kdb

我发现不同的 b_market_order_no where event=`OvernightOrder from tb table,使用任一方法

b_mkt_lst: select `g#b_market_order_no from tb where event=`OvernightOrder
b_mkt_lst: select distinct b_market_order_no from tb where  event=`OvernightOrder

对于该列表中具有 b_market_order_no 的所有记录,需要在另一个名为 tbp 的 table 中为该 b_market_order_no 找到 b_orig_date,我尝试了这两种方法:

select b_orig_date from tbp where b_market_order_no in b_mkt_lst
select b_orig_date from tbp each b_mkt_lst

第一个给我不兼容的长度,第二个不识别 b_orig_date,但 "select b_orig_date from tbp" 识别 return 个结果。

对您的数据做出一些假设:

q)t:([]c1:`a`b`c;c2:1 2 3)

/your length error is because you're comparing a list (b_market_order_no col) to a table (b_mkt_lst)
/similar to
q)select from t1 where c2 in select distinct c2 from ([]c2:1 3)
'length                        

/instead, use exec to extract a list (thus comparing a list to a list)
q)select from t1 where c2 in exec distinct c2 from ([]c2:1 3)
c1 c2
-----
a  1
c  3

/or turn the column(s) into a table to compare table to table
/(this is more useful when there's more than one column to compare)
q)select from t1 where ([]c2) in select distinct c2 from ([]c2:1 3)
c1 c2
-----
a  1
c  3