如何跨行对整数数组求和
How to sum integer arrays across rows
如何实现 summarize sum(Trend) by id
的等价物,其中 Trend
是整数数组?
Input:
——————————————————————————
Id | ParentId | Trend
——————————————————————————
C1-P1 | P1 | [1,2,3]
C2-P1 | P1 | [4,5,6]
C3-P1 | P1 | [1,1,1]
P1 | |
C1-P2 | P2 | [4,5,6]
C2-P2 | P2 | [7,8,9]
P2 | |
—————————————————————————-
Needed Output:
——————————————————————————
Id | ParentId | Trend
——————————————————————————
C1-P1 | P1 | [1,2,3]
C2-P1 | P1 | [4,5,6]
C3-P1 | P1 | [1,1,1]
P1 | | [6,8,10]
C1-P2 | P2 | [4,5,6]
C2-P2 | P2 | [7,8,9]
P2 | | [11,13,15]
—————————————————————————-
请检查以下查询是否解决了您的情况:
它使用 mv-expand operator and 'with_itemindex' option 来扩展数组的值。
let _data = datatable(Id:string, ParentId:string, Trend:dynamic)
[
'C1-P1','P1', dynamic([1,2,3]),
'C2-P1', 'P1', dynamic([4,5,6]),
'C3-P','P1',dynamic([1,1,1]),
'P1','',dynamic([]),
'C1-P2','P2',dynamic([4,5,6]),
'C2-P2','P2',dynamic([7,8,9]),
'P2', '', dynamic([])
];
_data
| mv-expand with_itemindex=x Trend to typeof(long)
| summarize sum(Trend) by ParentId, x
| summarize Trend=make_list(sum_Trend) by ParentId
| union (_data | where isnotempty( ParentId))
如何实现 summarize sum(Trend) by id
的等价物,其中 Trend
是整数数组?
Input:
——————————————————————————
Id | ParentId | Trend
——————————————————————————
C1-P1 | P1 | [1,2,3]
C2-P1 | P1 | [4,5,6]
C3-P1 | P1 | [1,1,1]
P1 | |
C1-P2 | P2 | [4,5,6]
C2-P2 | P2 | [7,8,9]
P2 | |
—————————————————————————-
Needed Output:
——————————————————————————
Id | ParentId | Trend
——————————————————————————
C1-P1 | P1 | [1,2,3]
C2-P1 | P1 | [4,5,6]
C3-P1 | P1 | [1,1,1]
P1 | | [6,8,10]
C1-P2 | P2 | [4,5,6]
C2-P2 | P2 | [7,8,9]
P2 | | [11,13,15]
—————————————————————————-
请检查以下查询是否解决了您的情况: 它使用 mv-expand operator and 'with_itemindex' option 来扩展数组的值。
let _data = datatable(Id:string, ParentId:string, Trend:dynamic)
[
'C1-P1','P1', dynamic([1,2,3]),
'C2-P1', 'P1', dynamic([4,5,6]),
'C3-P','P1',dynamic([1,1,1]),
'P1','',dynamic([]),
'C1-P2','P2',dynamic([4,5,6]),
'C2-P2','P2',dynamic([7,8,9]),
'P2', '', dynamic([])
];
_data
| mv-expand with_itemindex=x Trend to typeof(long)
| summarize sum(Trend) by ParentId, x
| summarize Trend=make_list(sum_Trend) by ParentId
| union (_data | where isnotempty( ParentId))