Kusto查询以dcount计算总数的百分比

问题描述

我是Kusto语言的新手,我正在尝试创建一个查询,以计算唯一用户级别的总数所占的百分比。 ratio列不返回任何结果-也许我做错了:/有更好的方法吗?

let T2 = T1 
|where timesstamp >ago(1m) and variable =='ss'
|summarize col_1 = dcount(user) by bin(timesstamp,1s)
;
let T3 = T1
|where timesstamp >ago(1m) and variable in ('ss','ss1','ss2','ss3')
|summarize col_2 = dcount(user) by bin(timesstamp,1s)
;
T3
| join T2 on timesstamp
|extend ratio =tolong(col_1/col_2)*100

解决方法

您可以尝试以下方法:

let T1 = datatable(timestamp:datetime,variable:string,user:string)
[
    datetime(2020-09-03 03:14:35),"ss","u1",datetime(2020-09-03 03:14:35),"ss1","ss2","u2",datetime(2020-09-03 03:14:36),datetime(2020-09-03 03:14:37),"ss3","u3",]
;
let T2 = T1 
    | where timestamp > ago(10m) and variable == 'ss'
    | summarize col_1 = dcount(user) by bin(timestamp,1s)
;
let T3 = T1
    | where timestamp > ago(10m) and variable in ('ss','ss1','ss2','ss3')
    | summarize col_2 = dcount(user) by bin(timestamp,1s)
;
T3
| join T2 on timestamp
| project timestamp,col_1,col_2,ratio = round(100.0 * col_1 / col_2,2)

--->

| timestamp                   | col_1 | col_2 | ratio |
|-----------------------------|-------|-------|-------|
| 2020-09-03 03:14:35.0000000 | 1     | 2     | 50    |
| 2020-09-03 03:14:36.0000000 | 1     | 1     | 100   |
| 2020-09-03 03:14:37.0000000 | 2     | 3     | 66.67 |

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...