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

Azure Data Explorer查询指定时段未发送心跳用户的语句问题

问题原因及解决方案

你的查询逻辑存在问题:当用左连接筛选出从未发送过心跳的用户时,这些用户的HeartBeatDate字段值为null,后续添加的时间范围条件HeartBeatDate between (...)会直接排除所有null值的记录,导致无结果返回。

要筛选指定时间范围内未发送心跳的用户,正确逻辑如下:

  1. 先从Heartbeat表中提取指定时间范围内有心跳记录的用户列表
  2. 用Users表左连接这个筛选后的列表,找出未匹配上的用户(即该时间段内无心跳的用户)

修正后的Kusto查询:

// 获取指定时间内有心跳记录的用户
let active_users = Heartbeat
| where HeartBeatDate between (datetime('2024-07-14 16:04:10')..datetime('2024-07-15 16:04:10'))
| distinct userEmail;

// 从用户表中排除有心跳的用户,得到目标结果
Users
| join kind=leftouter active_users on userEmail
| where isempty(userEmail1)  // 筛选未匹配到的用户(该时间段无心跳)
| distinct userLoginName, userEmail, userFullName, userPicture, userCreateDate, userPhoneNumber

另外,原查询中userEmail1 !has (userEmail)的写法不够严谨,判断左连接后右表无匹配的标准写法是isempty(userEmail1)(适配字段为空的场景)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 01:40:01