Skip to content

ORDER BY

一句话解释

ORDER BY 排序查询 results 通过 specified 列, 要么 ascending (ASC) or descending (DESC).

用大白话说

ORDER BY 排序行 in result 设置. 你 specify one or 更多列 and 方向 — ASC (ascending, 默认) or DESC (descending).

You can sort by multiple columns: the first column is the primary sort key, and subsequent columns break ties. For example, ORDER BY last_name ASC, first_name ASC sorts by last name, then by first name for people with the same last name.

ORDER BY is applied after WHERE, GROUP BY, and HAVING — it sorts the final result set. It can be slow on large result sets without an index on the sort column.

示例

sql
-- Sort users by creation date, newest first
SELECT * FROM users
ORDER BY created_at DESC;

-- Sort by last name, then first name
SELECT * FROM users
ORDER BY last_name ASC, first_name ASC;

首先查询排序 newest-首先. 其次排序通过最后 name, breaking ties 使用首先 name.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表