4

有这个输入:

let t1 = datatable(id:string, col1:string, col2:string)
[
    '1', 'col1_1', 'col2_1',
    '2', 'col1_2', 'col2_2',
    '3', 'col1_3', 'col2_3',
    '4', 'col1_4', 'col2_4',
    '1', 'col1_1', 'col2_11',
];
t1 
| distinct id, col1

我需要一个查询,它只选择“id”字段中具有唯一值的行。我知道有两种可能的输出:

输出 1:

'1', 'col1_1', 'col2_1',
'2', 'col1_2', 'col2_2',
'3', 'col1_3', 'col2_3',
'4', 'col1_4', 'col2_4',

输出 2:

'2', 'col1_2', 'col2_2',
'3', 'col1_3', 'col2_3',
'4', 'col1_4', 'col2_4',
'1', 'col1_11', 'col2_11',
4

2 回答 2

12

您可以使用any()聚合函数根据“id”列中的唯一值获取 col1 和 col2 值。

let t1 = datatable(id:string, col1:string, col2:string)
[
    '1', 'col1_1', 'col2_1',
    '2', 'col1_2', 'col2_2',
    '3', 'col1_3', 'col2_3',
    '4', 'col1_4', 'col2_4',
    '1', 'col1_1', 'col2_11',
];
t1 
| summarize any(col1), any(col2) by id
于 2018-10-16T22:49:05.357 回答
0

这会满足您的需求吗?

let t1 = datatable(id:string, col1:string, col2:string)
[
    '1', 'col1_1', 'col2_1',
    '2', 'col1_2', 'col2_2',
    '3', 'col1_3', 'col2_3',
    '4', 'col1_4', 'col2_4',
    '1', 'col1_1', 'col2_11',
];
t1 
| summarize col1 = make_set( col1 ), col2 = make_set( col2 ) by id
于 2019-12-13T19:28:52.140 回答