You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在已有时间范围的KQL查询中筛选周一至周五工作日数据?

KQL筛选工作日(周一至周五)数据的实现方法

问题描述

现有一段KQL查询代码,已通过timestamp between (datetime(06:00) .. datetime(15:00))限制每日时间范围,希望在此基础上进一步筛选周一至周五的工作日数据,询问具体实现方法。

查询代码示例:

availabilityResults
| where timestamp between (datetime(06:00) .. datetime(15:00))
| where true
| where name == "warmup" and true
| extend percentage = toint(success) * 100
| render timechart

解决方案

可以利用KQL内置的dayofweek()函数实现工作日筛选。该函数返回0-6的整数,对应星期几的关系为:

  • 0 = 周日
  • 1 = 周一
  • 2 = 周二
  • 3 = 周三
  • 4 = 周四
  • 5 = 周五
  • 6 = 周六

只需在查询中添加一个where条件,筛选返回值为1到5的记录即可。修改后的完整查询如下:

availabilityResults
| where timestamp between (datetime(06:00) .. datetime(15:00))
| where dayofweek(timestamp) between (1 .. 5) // 筛选周一至周五
| where name == "warmup"
| extend percentage = toint(success) * 100
| render timechart

说明

  • 新增的where dayofweek(timestamp) between (1 .. 5)语句会保留周一到周五、且符合每日时间范围的数据
  • 原查询中冗余的| where true可直接移除,不影响查询逻辑

内容的提问来源于stack exchange,提问作者Phil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 05:10:21