简体   繁体   English

如何在 Kusto 中查询具有 null 和非空值的分组不同记录?

[英]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 - 提供具有非空字符串(或空集)的集合
  • last, by accessing the first element of the result set (using [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.

相关问题 分组数据集中的 Bigquery 非空(地理点) - Bigquery non-null(geographypoint) in grouped dataset 在 SQL 中无需手动输入即可一次计算多列中的非空值 - Count non-null values from multiple columns at once without manual entry in SQL 在 bigQuery 中仅返回非空键/值 - Returning only non-null key/value in bigQuery 获取多个分区中的下一个(或上一个)非空值 - Get the next (or previous) non-null value in multiple partitioned 未处理的异常:PlatformException(空错误,主机平台为非空返回值返回 null 值。,null,空) - Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null) FirebaseCloudMessaging: PlatformException (PlatformException(null-error, Host platform returned null value for non-null return value., null, null)) - FirebaseCloudMessaging : PlatformException (PlatformException(null-error, Host platform returned null value for non-null return value., null, null)) 如何在 Kusto 查询中匹配多个值 - How to match multiple values in Kusto Query 必须返回非空值,因为返回类型“UserCredentialPlatform”不允许空值 - A non-null value must be returned since the return type 'UserCredentialPlatform' doesn't allow null 在 ADX 表上分页。 如何跳过 kusto 查询语言中的记录 - Paging on ADX table. how to skip the records in kusto query language 错误:必须返回非空值,因为返回类型“从不”不允许 null - Error: A non-null value must be returned since the return type 'Never' doesn't allow null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM