在KQL查询中是否可以获取第二行(仅限第二行)?

huangapple go评论89阅读模式
英文:

Is it possible to get 2nd row (only) in a KQL query?

问题

I am sorting (desc) my records by timestamp.
我正在按时间戳排序我的记录(降序)。

While I can easily take 1 to return the latest record (first row while sorting by timestamp), is it possible to take the second?
虽然我可以轻松使用 take 1 返回最新的记录(在按时间戳排序时的第一行),但是否可能取第二行?

Is there a "skip" operator as in C# Linq?
是否有像C# Linq中的“skip”运算符?

using take 2 will return both records.
使用 take 2 将返回两条记录。

英文:

I am querying a MS AI database using KQL.

I am sorting (desc) my records by timestamp.

While I can easily take 1 to return the latest record (first row while sorting by timestamp), is it possible to take the second?

Is there a "skip" operator as in C# Linq?

using take 2 will return both records.

答案1

得分: 0

使用ADX的row_rank_dense()函数,您可以获取记录的排名,然后使用扩展的rank列上的where来筛选第n条记录。

请参考此处了解更多信息。

以下是带有示例数据的示例查询。

datatable (timeStamp : datetime , str :string )
[
datetime("2023,03,13"),"aaa",
datetime("2023,03,14"),"bbb",
datetime("2023,03,15"),"ccc",
datetime("2023,03,11"),"ddd",
datetime("2023,03,16"),"eee",
datetime("2023,03,16"),"fff"
]
| order by timeStamp desc
| extend rank = row_rank_dense(timeStamp)
| where rank == 2
| project-away rank

结果

在KQL查询中是否可以获取第二行(仅限第二行)?

英文:

Using row_rank_dense() function of ADX you can get ranks of the records and then using where on extended rank column you can filter the nth record.

Please refer here to read more about it.

Below is sample query with sample data.

datatable (timeStamp : datetime , str :string )
[
datetime("2023,03,13"),"aaa",
datetime("2023,03,14"),"bbb",
datetime("2023,03,15"),"ccc",
datetime("2023,03,11"),"ddd",
datetime("2023,03,16"),"eee",
datetime("2023,03,16"),"fff"
]
| order by timeStamp desc
| extend rank = row_rank_dense(timeStamp)
| where rank == 2
| project-away rank

Result

在KQL查询中是否可以获取第二行(仅限第二行)?

huangapple
  • 本文由 发表于 2023年4月13日 18:09:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76004211.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定