带有OR条件的KDB查询,就像在SQL中一样

时间:2014-11-12 12:32:41

标签: kdb q-lang

在SQL中,我可以用逻辑(true和true)或(true和true)来编写查询,即:

select * from t1 inner join t2 on ... where (t1.a != t2.a and t1.b != t2.b) or (t1. != t2.a and t1.b != t2.b)

当我尝试在Q中这样做时

select from ej[....] where (t1.a != t2.a and t1.b != t2.b) or (t1. != t2.a and t1.b != t2.b)

无法编译。

我也试过这个

(t1.a != t2.a and t1.b != t2.b) or (t1. != t2.a and t1.b != t2.b)

但它没有返回正确的结果

如何在KDB中查询?

1 个答案:

答案 0 :(得分:1)

试试这个(伪代码):

( (t1.a != t2.a) and (t1.b != t2.b) ) or ( (t1.a != t2.a) and (t1.b != t2.b) )

Kdb / Q读取左侧,因此它处理

t1.a != t2.a and t1.b != t2.b

作为

t1.a != (t2.a and t1.b != t2.b)

而不是

(t1.a != t2.a) and (t1.b != t2.b)

除非你明确使用括号

相关问题