[英]How to query for grouped distinct records that both have null and non-null values in Kusto?
I am trying to create a query that returns a result set with a distinct (car) column based on another (data) column that is non-null.我正在尝试创建一个查询,该查询返回一个结果集,该结果集具有基于另一个非空(数据)列的不同(汽车)列。
In the example below, if there is a non-null value found in the data column then return the single instance with a value and if not, return the value with null and always maintain the distinctness of the first column.在下面的示例中,如果在数据列中找到非空值,则返回带有值的单个实例,如果没有,则返回带有 null 的值,并始终保持第一列的独特性。
let Car = datatable(car, data:string)
[
"mercedes", "fast",
"mercedes", null,
"tesla", null
"toyota", "good",
"sonata", null,
"sonata", null,
"sonata", "amazing"
];
So the desired output would be:所以所需的 output 将是:
"mercedes", "fast",
"tesla", null,
"toyota", "good",
"sonata", "amazing",
Thanks!谢谢!
one option would be using a combination of set_difference()
and make_set()
:一种选择是结合使用
set_difference()
和make_set()
:
make_set()
will create a set of all unique values of data
(by car
, the aggregation key) make_set()
将创建一组data
的所有唯一值(通过car
,聚合键)dynamic([""])
is an array with an empty string dynamic([""])
是一个带有空字符串的数组set_difference()
will produce the difference between the two former arrays - to provide a set with a non-empty string (or an empty set) set_difference()
将产生两个前者之间的差异 arrays - 提供具有非空字符串(或空集)的集合[0]
), you'll get the first element that's not-empty (or null, if the set is empty)[0]
),您将获得第一个非空元素(或 null,如果集合为空)datatable(car:string, data:string)
[
"mercedes", "",
"mercedes", "fast",
"tesla", "",
"toyota", "good",
"sonata", "",
"sonata", "",
"sonata", "amazing"
]
| summarize data = set_difference(make_set(data), dynamic([""]))[0] by car
car![]() |
data![]() |
---|---|
mercedes![]() |
fast![]() |
tesla![]() |
|
toyota![]() |
good![]() |
sonata![]() |
amazing![]() |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.