英文:
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
结果
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论