order 运算符、sort 运算符

按照一个或多个列的顺序对输入表的行排序。

ordersort 运算符是等效的

语法

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

参数

名称 Type 需要 说明
T 字符串 要排序的表格输入。
column 标量 (scalar) T 的列,用作排序依据。 列值的类型必须是数字、日期、时间或字符串。
ascdesc 字符串 asc 按升序排序(从低到高)。 默认值为 desc(从高到低)。
nulls firstnulls last 字符串 nulls first 将把 null 值放在开头,nulls last 将把 null 值放在末尾。 asc 的默认值是 nulls firstdesc 的默认值是 nulls last

返回

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

示例

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

StormEvents
| order by State asc, StartTime desc

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

StartTime 状态 EventType ...
2007-12-28T12:10:00Z ALABAMA 冰雹 ...
2007-12-28T04:30:00Z ALABAMA 冰雹 ...
2007-12-28T04:16:00Z ALABAMA 冰雹 ...
2007-12-28T04:15:00Z ALABAMA 冰雹 ...
2007-12-28T04:13:00Z ALABAMA 冰雹 ...
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 ...