首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在数组中打印不同的值

在数组中打印不同的值
EN

Stack Overflow用户
提问于 2018-03-15 00:42:56
回答 1查看 978关注 0票数 0

我有一个列,它是一个数组,希望打印不同的计数。

代码语言:javascript
复制
Event
| project colors

Present OutPut

代码语言:javascript
复制
["Red", "Green", "Green", "Red"]
["Yellow", "Yellow", "Yellow", "Yellow"]

期望

代码语言:javascript
复制
["Red", "Green", "Green", "Red"] , 2
["Yellow", "Yellow", "Yellow", "Yellow"], 1
EN

回答 1

Stack Overflow用户

发布于 2018-03-16 18:56:19

下面是我认为您想要的,使用todynamicmvexpandsummarize (以及创建输入数据的datatable )

代码语言:javascript
复制
// create your sample data using datatable to make a 'fake' table
datatable (colors: string) [
'["Red", "Green", "Green", "Red"]',
'["Yellow", "Yellow", "Yellow", "Yellow"]'
]
// this part is answering your question
| extend c = todynamic(colors) // turns colors into arrays
| mvexpand c // expands all the values out of colors into their own rows (but each column value is still "dynamic" type)
| extend c = tostring(c) // turn the dynamic c column to strings to summarize the values
| summarize ["Count"] = dcount(c) by colors // count up distinct c values by each row

这将输出您在问题中所包含的内容:

代码语言:javascript
复制
colors                                     Count 
------------------------------------------------
["Red", "Green", "Green", "Red"]           2 
["Yellow", "Yellow", "Yellow", "Yellow"]   1 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49289845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档