简体   繁体   English

Kusto 相当于 SQL 不在

[英]Kusto equivalent of SQL NOT IN

I am trying to identify what records exist in table 1 that are not in table 2 (so essentially using NOT IN)我试图确定表 1 中存在哪些记录不在表 2 中(所以基本上使用 NOT IN)

let outliers =
Table 2
| project UniqueEventGuid;
Table 1
|where UniqueEventGuid !in  (outliers)
|project UniqueEventGuid

but getting 0 records back even though I know there are orphans in table 1. Is the !in not the right syntax?但是即使我知道表 1 中有孤儿,也得到了 0 条记录。 !in不是正确的语法吗?

Thanks in advance!提前致谢!

!in operator !in 运算符

"In tabular expressions, the first column of the result set is selected." “在表格表达式中,结果集的第一列被选中。”

In the following example I intentionally ordered the column such that the query will result in error due to mismatched data types.在下面的示例中,我有意对列进行排序,以便查询由于数据类型不匹配而导致错误。

In your case, the data types might match, so the query is valid, but the results are wrong.在您的情况下,数据类型可能匹配,因此查询有效,但结果错误。

let t1 = datatable(i:int, x:string)[1,"A", 2,"B", 3,"C" ,4,"D" ,5,"E"];
let t2 = datatable(y:string, i:int)["d",4 ,"e",5 ,"f",6 ,"g",7];
t1
| where i !in (t2)

Relop semantic error: SEM0025: One of the values provided to the ',in' operator does not match the left side expression type 'int', consider using explicit cast Relop 语义错误:SEM0025:提供给“,in”运算符的值之一与左侧表达式类型“int”不匹配,请考虑使用显式强制转换

Fiddle 小提琴

If that is indeed the case, you can reorder the columns or project only the relevant one.如果确实如此,您可以重新排序列或仅投影相关的列。
Note the use of double brackets.注意使用双括号。

let t1 = datatable(i:int, x:string)[1,"A", 2,"B", 3,"C" ,4,"D" ,5,"E"];
let t2 = datatable(y:string, i:int)["d",4 ,"e",5 ,"f",6 ,"g",7];
t1
| where i !in ((t2 | project i))
i一世 x X
1 1 A一个
2 2 B
3 3 C C

Fiddle 小提琴

Another option is to use leftanti join另一种选择是使用leftanti join

let t1 = datatable(i:int, x:string)[1,"A", 2,"B", 3,"C" ,4,"D" ,5,"E"];
let t2 = datatable(y:string, i:int)["d",4 ,"e",5 ,"f",6 ,"g",7];
t1
| join kind=leftanti t2 on i
i一世 x X
2 2 B
3 3 C C
1 1 A一个

Fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM