order()

按列对查询结果进行排序。

  • 你可以多次调用这个方法来按多列排序。

  • 你可以对外部表进行排序,但这并不影响对当前表的排序。

案例教程

案例1 (使用select)#

1create table
2  countries (id int8 primary key, name text);
3
4insert into
5  countries (id, name)
6values
7  (1, 'Afghanistan'),
8  (2, 'Albania'),
9  (3, 'Algeria');

案例2 (在外部表)#

1create table
2  countries (id int8 primary key, name text);
3create table
4  cities (
5    id int8 primary key,
6    country_id int8 not null references countries,
7    name text
8  );
9
10insert into
11  countries (id, name)
12values
13  (1, 'United States'),
14  (2, 'Vanuatu');
15insert into
16  cities (id, country_id, name)
17values
18  (1, 1, 'Atlanta'),
19  (2, 1, 'New York City');

参数说明

  • 列(column)[必要参数]
    string类型

    要排序的列

  • 选项(option)[可选参数]
    [可选参数]

    命名的参数

      特性
    • foreignTable[必要参数]
      string类型

      设置此选项以按外域表的列

    • ascending[可选参数]
      boolean类型

      如果 "true",结果将按升序排列。

    • nullsFirst[可选参数]
      boolean

      如果 true,null首先出现。如果 false,则 null 出现在最后。