长期使用传统SQL,习惯了order by
和limit
,top
是MS自带的“limit”但更直观。
这里两个 Kusto 查询共享相同的条件和顺序(排序,对吧?),唯一的区别是返回多少,20 与 200。结果令人惊讶:
AzureDiagnostics | where Category contains "postgresql" | take 20 | order by TimeGenerated desc
AzureDiagnostics | where Category contains "postgresql" | take 200 | order by TimeGenerated desc
顶部更加一致
AzureDiagnostics | where Category contains "postgresql" | top 2 by TimeGenerated desc
AzureDiagnostics | where Category contains "postgresql" | top 20 by TimeGenerated desc
更新,感谢@Yoni L,总结如下:
- 每个
|
部分的顺序很重要。例如,|take 10 | order by x
将在take
之后排序,这是随机的。 采取
=使用限制
排序依据
=排序依据
按 x [asc/desc] 排序的前 10 名
=按 x [asc/desc] 排序 |取 10
,但top X by Y
使用的内存要少得多,应该是首选。
最佳答案
与top
不同,对于take
和limit
(它们是别名),不保证返回哪些记录,除非源数据是已排序。
以下内容是等效的 - top 20 by x desc
、order by x desc | take 20
,但这有不同的语义:take 20 | order by x desc
- 它仅对 take
n
关于azure - Take vs. Limit vs. Top、Sort vs. Order By,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71253759/