我有张桌子上有这样的数据:-
-----------------------------------------------------------------------------
Audience | A_Types | B_Types | C_Types | D_Types | IsTall | IsRed | IsHeavy |
-----------------------------------------------------------------------------
Noah | 3,4,5 | 1,2,5 | 1,5,6 | 1,2,3 | 0 | 1 | 1 |
-----------------------------------------------------------------------------
Rebecca | 3,4,4,6 | 1,2,3,4 | 2,3,4,5 | 2,3,4,5 | 1 | 0 | 0 |
-----------------------------------------------------------------------------
Noah | 3,4 | 1,2 | 1,5 | 1,2 | 0 | 1 | 1 |
-----------------------------------------------------------------------------额外信息:
下面的行不允许存在。
-----------------------------------------------------------------------------
Audience | A_Types | B_Types | C_Types | D_Types | IsTall | IsRed | IsHeavy |
-----------------------------------------------------------------------------
Noah | 3,4,5 | 1,2 | | 1,2,3 | 0 | 1 | 1 |
-----------------------------------------------------------------------------
Rebecca | 3,4 | 1,2,3,4 | | 2,3 | 0 | 1 | 1 |
-----------------------------------------------------------------------------对于任何给定的行,
我想得到在"Is*“列的值、受众和"*_Types”列的单独值上汇总的所有内容的数量。
我写了以下查询:-
TableName
| where Audience in ("Noah", "Rebecca", "Puyol", "Enkir", "Doman")
| extend A_Types = split(A_Types, ",")
| extend B_Types = split(B_Types, ",")
| extend C_Types = split(C_Types, ",")
| extend D_Types = split(D_Types, ",")
| mv-expand A_Type = A_Types to typeof(string)
| mv-expand B_Type = B_Types to typeof(string)
| mv-expand C_Type = C_Types to typeof(string)
| mv-expand D_Type = D_Types to typeof(string)
| summarize count() by
A_Type,
B_Type,
C_Type,
D_Type,
IsRed,
IsTall,
IsHeavy,
Audience我看到一些与上面的查询结果不一致的地方,有人能建议一个更好的查询或者如果这个查询是正确的可以评论吗?
发布于 2021-03-07 06:55:22
您需要在一次操作中为相关列执行mv-展开,以便在同一行的每个数组中获得匹配的值。例如:
let Data = datatable(Audience:string, A_Types:dynamic, B_Types:dynamic, C_Types:dynamic, D_Types:dynamic, IsTall:int, IsRed:int, IsHeavy:int)
["Noah", dynamic([3,4,5]), dynamic([1,2,5]), dynamic([1,5,6]), dynamic([ 1,2,3]), 0 ,1 , 1,
"Rebecca", dynamic([3,4,4,6]), dynamic([1,2,3,4]), dynamic([2,3,4,5]), dynamic([2,3,4,5]), 1 , 0 ,0,
"Noah", dynamic([3,4]), dynamic([1,2]), dynamic([1,5]), dynamic([ 1,2]), 0 ,1 , 1];
Data
| mv-expand A_Types to typeof(int), B_Types to typeof(int), C_Types to typeof(int), D_Types to typeof(int)
| summarize sum(IsTall), sum(IsHeavy), sum(IsRed) by Audience, A_Types, B_Types, C_Types, D_Types结果:

https://stackoverflow.com/questions/66508338
复制相似问题