ORDER BY对SELECT语句检索得到的一列或者多列数据进行升序(ASC)或者降序(DESC)排列。
SELECT
{ * | [column, ...] }
[ FROM from_item [, ...] ]
[ ORDER BY {expression [ ASC | DESC ] }];
ORDER BY子句
对SELECT语句检索得到的数据进行升序或降序排序。对于ORDER BY表达式中包含多列的情况:
对结果根据c_customer_sk字段值进行升序排列。
openGauss=# SELECT * FROM customer_t1 ORDER BY c_customer_sk ASC;
c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
3869 | hello | Grace | | 1000
3869 | hello | Grace | | 1000
3869 | | Grace | |
3869 | hello | | |
3869 | hello | | |
4421 | Admin | Local | | 3000
6985 | maps | Joes | | 2200
9976 | world | James | | 5000
| | | |
(9 rows)
对结果根据c_customer_sk字段值进行降序排列。
openGauss=# SELECT * FROM customer_t1 ORDER BY c_customer_sk DESC;
c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
| | | |
9976 | world | James | | 5000
6985 | maps | Joes | | 2200
4421 | Admin | Local | | 3000
3869 | hello | Grace | | 1000
3869 | hello | | |
3869 | hello | Grace | | 1000
3869 | | Grace | |
3869 | hello | | |
(9 rows)
点赞,你的认可是我创作的动力!
⭐️ 收藏,你的青睐是我努力的方向!
✏️ 评论,你的意见是我进步的财富!