如何在子选择中使用过滤器
How to use a filter in subselect
我想对一组相关数据执行子选择。该子数据需要使用主查询中的数据进行过滤:
customEvents
| extend envId = tostring(customDimensions.EnvironmentId)
| extend organisation = tostring(customDimensions.OrganisationName)
| extend version = tostring(customDimensions.Version)
| extend app = tostring(customDimensions.Appname)
| where customDimensions.EventName contains "ApiSessionStartStart"
| extend dbInfo = toscalar(
customEvents
| extend dbInfo = tostring(customDimensions.dbInfo)
| extend serverEnvId = tostring(customDimensions.EnvironmentId)
| where customDimensions.EventName == "ServiceSessionStart" or customDimensions.EventName == "ServiceSessionContinuation"
| where serverEnvId = envId // This gives and error
| project dbInfo
| take 1)
| order by timestamp desc
| project timestamp, customDimensions.OrganisationName, customDimensions.Version, customDimensions.onBehalfOf, customDimensions.userId, customDimensions.Appname, customDimensions.apiKey, customDimensions.remoteIp, session_Id , dbInfo, envId
以上查询结果报错:
Failed to resolve entity 'envId'
如何根据主查询中的字段 envId
筛选子查询中的数据?
我相信您需要使用 join
来代替,您可以在其中加入以从第二个查询中获取该值
加入文档:https://docs.loganalytics.io/docs/Language-Reference/Tabular-operators/join-operator
联接的左侧是您的 "outer" 查询,联接的右侧是 "inner" 查询,但您可能不会执行 take 1做一个更简单的查询,只获取 serverEnvId、dbInfo
的不同值
我想对一组相关数据执行子选择。该子数据需要使用主查询中的数据进行过滤:
customEvents
| extend envId = tostring(customDimensions.EnvironmentId)
| extend organisation = tostring(customDimensions.OrganisationName)
| extend version = tostring(customDimensions.Version)
| extend app = tostring(customDimensions.Appname)
| where customDimensions.EventName contains "ApiSessionStartStart"
| extend dbInfo = toscalar(
customEvents
| extend dbInfo = tostring(customDimensions.dbInfo)
| extend serverEnvId = tostring(customDimensions.EnvironmentId)
| where customDimensions.EventName == "ServiceSessionStart" or customDimensions.EventName == "ServiceSessionContinuation"
| where serverEnvId = envId // This gives and error
| project dbInfo
| take 1)
| order by timestamp desc
| project timestamp, customDimensions.OrganisationName, customDimensions.Version, customDimensions.onBehalfOf, customDimensions.userId, customDimensions.Appname, customDimensions.apiKey, customDimensions.remoteIp, session_Id , dbInfo, envId
以上查询结果报错:
Failed to resolve entity 'envId'
如何根据主查询中的字段 envId
筛选子查询中的数据?
我相信您需要使用 join
来代替,您可以在其中加入以从第二个查询中获取该值
加入文档:https://docs.loganalytics.io/docs/Language-Reference/Tabular-operators/join-operator
联接的左侧是您的 "outer" 查询,联接的右侧是 "inner" 查询,但您可能不会执行 take 1做一个更简单的查询,只获取 serverEnvId、dbInfo
的不同值