如何在第2张表中求不存在于第1张表的记录


您好有个编程的问题。现在有表A,B,二者都有symbol,time,order_id的3列。

我想把表B中(symbol,order_id)不存在于表A的样本筛选出来做(symbol,order_id)的聚合运算,有不需要left_join的筛选方法吗?

类似于select count(*) from B group by (symbol, order_id) having (symbol, order_id) not in (A.symbol, A.order_id) 

比如下面表A和B:

symbol=`a`a`a`b`b`b`c`c`c
order_id=1 2 3 1 2 3 1 2 3 
A = table(symbol, date,order_id)
order_id = 1 2 3 1 2 4 1 2 4
B =table(symbol, date,order_id)

执行select * from lj(A,B,`symbol`order_id) where B.date=NULL后,结果如下:
attachments-2021-08-hlSo4fiQ6114c791eaabb.png
请先 登录 后评论

1 个回答

wale

用conditionalFilter试试:

symbol=`a`a`a`b`b`b`c`c`c
order_id=1 2 3 1 2 3 1 2 3 
A = table(symbol, date,order_id)
order_id = 1 2 3 1 2 4 1 2 4
B =table(symbol, date,order_id)
timer(1000) {
filter1= dict(STRING, ANY)
filter1.dictUpdate!(append!, A.symbol, A.order_id, x->array(x.type(), 0, 512).append!(x))
select * from B where not conditionalFilter( order_id,symbol,filter1) 
}//执行1000次耗费77ms
timer(1000) select * from lj(A,B,`symbol`order_id) where B.date=NULL //执行1000次耗费183ms

在我电脑上测试,conditionalFilter的性能比lj提高约1倍。

请先 登录 后评论