你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

sort operator

Applies to: ✅Microsoft FabricAzure Data ExplorerAzure MonitorMicrosoft Sentinel

按一列或多列的顺序对输入表中的行进行排序。

sortorder 运算符是等效的

Syntax

T| sort bycolumn [asc | desc] [nulls first | nulls last] [, ...]

Learn more about syntax conventions.

Parameters

Name 类型 Required Description
T string ✔️ 要排序的表格输入。
column scalar ✔️ The column of T by which to sort. 列值的类型必须是数字、日期、时间或字符串。
ascdesc string asc 按升序排序(从低到高)。 默认值为 desc(从高到低)。
nulls firstnulls last string nulls first 将把 null 值放在开头,nulls last 将把 null 值放在末尾。 asc 的默认值是 nulls firstdesc 的默认值是 nulls last

Returns

根据提供的列按升序或降序排序的输入表副本。

使用特殊浮点值

当输入表包含特殊值 nullNaN-inf+inf 时,顺序将如下所示:

Value Ascending Descending
Nulls first null、、NaN-inf-505+inf null,,NaN+inf50-5
Nulls last -inf,,-50+infNaNnull +inf,,50-5NaNnull

Note

  • null 和 NaN 值始终组合在一起。
  • null 和 NaN 值之间的顺序由第一个和最后一个属性确定,因为 null 和 NaN 没有升序和降序。

Example

以下示例按州的字母顺序显示暴风雨事件,每个州最近发生的风暴先显示。

The examples in this article use publicly available tables in the help cluster, such as the StormEvents table in the Samples database.

The examples in this article use publicly available tables, such as the Weather table in the Weather analytics sample gallery. 可能需要修改示例查询中的表名称以匹配工作区中的表。

StormEvents
| sort by State asc, StartTime desc

Output

此表仅显示前 10 个查询结果。

StartTime State EventType ...
2007-12-28T12:10:00Z ALABAMA Hail ...
2007-12-28T04:30:00Z ALABAMA Hail ...
2007-12-28T04:16:00Z ALABAMA Hail ...
2007-12-28T04:15:00Z ALABAMA Hail ...
2007-12-28T04:13:00Z ALABAMA Hail ...
2007-12-21T14:30:00Z ALABAMA Strong Wind ...
2007-12-20T18:15:00Z ALABAMA Strong Wind ...
2007-12-20T18:00:00Z ALABAMA Strong Wind ...
2007-12-20T18:00:00Z ALABAMA Strong Wind ...
2007-12-20T17:45:00Z ALABAMA Strong Wind ...
2007-12-20T17:45:00Z ALABAMA Strong Wind ...