使用Kusto Query Language检查10行数据中是否存在6行Count值为0
使用Kusto查询语言检查10行数据中是否存在任意6行Count值为0
我有10行包含Time和Count两列的数据,需要通过Kusto Query Language检查这10行中是否存在任意6行的Count值为0。数据示例如下:
| Time | Count |
|---|---|
| 2022-09-01 17:23:00.000 | 70 |
| 2022-09-01 17:24:00.000 | 150 |
| 2022-09-01 17:25:00.000 | 300 |
| 2022-09-01 17:26:00.000 | 160 |
| 2022-09-01 17:27:00.000 | 210 |
| 2022-09-01 17:28:00.000 | 316 |
| 2022-09-01 17:29:00.000 | 265 |
| 2022-09-01 17:30:00.000 | 711 |
| 2022-09-01 17:31:00.000 | 185 |
| 2022-09-01 17:32:00.000 | 250 |
方案1:统计所有Count为0的总行数是否达标
如果只需要判断数据中Count为0的总行数是否≥6,用以下查询(替换YourTable为你的实际表名):
YourTable | summarize ZeroCount = countif(Count == 0) | extend HasSixZeros = ZeroCount >= 6
查询结果会返回两列:ZeroCount(Count为0的总行数)和HasSixZeros(布尔值,true表示满足条件)。
方案2:检查是否存在连续6行Count为0
如果需要验证是否存在连续的6行Count为0,用窗口函数实现:
YourTable | sort by Time asc // 按时间排序确保顺序正确 | extend IsZero = Count == 0 | extend ConsecutiveZeros = row_cumsum(IsZero, not(IsZero)) // 计算连续0的行数,遇到非0行重置 | summarize MaxConsecutiveZeros = max(ConsecutiveZeros) | extend HasSixConsecutiveZeros = MaxConsecutiveZeros >= 6
结果中的MaxConsecutiveZeros是最大连续0的行数,HasSixConsecutiveZeros会返回是否存在连续6行0的判断结果。
内容的提问来源于stack exchange,提问作者VKR
相关产品推荐
相关产品推荐

