sql limit 子句_SQL按子句排序

sql limit 子句

SQL排序依据 (SQL Order By)

  • SQL Order By clause is used for sorting the result set.

    SQL Order By子句用于对结果集进行排序。
  • The sorting is done in either ascending or in descending order.

    排序以升序或降序进行。
  • The default order of sorting is sorting in ascending order.

    默认的排序顺序是升序排序。
  • SQL Order By clause is used with SQL Select queries. Sorting is done after the result set is obtained

    SQL Order By子句与SQL Select查询一起使用。 获得结果集后进行排序
  • We can use multiple columns with order by clause, sorting will happen from left side columns first and then towards the left side columns. We will look at sql order by example with multiple columns to understand this scenario.

    我们可以在order by子句中使用多个列,排序将首先从左侧的列开始,然后再朝左侧的列进行。 我们将通过带有多个列的示例来查看sql order以了解这种情况。

SQL语法排序 (SQL Order By Syntax)

Let’s now try to understand syntax for SQL ORDER BY clause. Below is the syntax for getting results in ascending order.

现在,让我们尝试了解SQL ORDER BY子句的语法。 以下是按升序获取结果的语法。

SELECT column FROM table_name ORDER BY column asc;

In the syntax above the column, data is retrieved in ascending order.

在该列上方的语法中,数据以升序检索。

Let’s try to understand the ORDER BY command for ascending order through some example.

让我们尝试通过一些示例来理解ORDER BY命令的升序。

Let us consider the following Customer Table to understand ORDER BY command.

让我们考虑以下客户表,以了解ORDER BY命令。

CustomerIdCustomerNameCustomerAgeCustomerGender
1John31M
2Amit25M
3Annie35F
4null38M
顾客ID 顾客姓名 客户年龄 客户性别
1个 约翰 31 中号
2 阿米特 25 中号
3 安妮 35 F
4 空值 38 中号

Scenario: Retrieve name of the customers in ascending order.

场景 :按升序检索客户名称。

Query:

查询

SELECT CutomerName FROM Customer ORDER BY CustomerName asc;
CustomerName
null
Amit
Annie
John
顾客姓名
空值
阿米特
安妮
约翰

SQL按多列排序 (SQL Order By Multiple Columns)

We can sort the data based on multiple columns also. Let’s consider the following scenario to understand multiple column sorting.

我们还可以基于多个列对数据进行排序。 让我们考虑以下情形,以了解多列排序。

Scenario: Retrieve customer data based on CustomerGender and CustomerName in ascending order.

场景 :基于CustomerGender和CustomerName升序检索客户数据。

Query:

查询:

SELECT * FROM Customer ORDER BY CustomerGender, CustomerName ASC;

Output:

输出

CustomerIdCustomerNameCustomerAgeCustomerGender
3Annie35F
4null38M
2Amit25M
1John31M
顾客ID 顾客姓名 客户年龄 客户性别
3 安妮 35 F
4 空值 38 中号
2 阿米特 25 中号
1个 约翰 31 中号

Notice that first sorting is done on gender and then on the name. By default “null” values comes first in ascending order values.

注意,首先对性别进行排序,然后对名称进行排序。 默认情况下,“ null”值在升序值中排在首位。

SQL降序排列 (SQL Order By Descending)

SELECT column FROM table_name ORDER BY column desc;

In the syntax above the column, data is retrieved in descending order.

在该列上方的语法中,数据以降序检索。

Let’s try to understand the ORDER BY command for descending through some example. We will use the Customer table provided above for our example.

让我们尝试了解ORDER BY命令,以了解一些示例。 我们将使用上面提供的Customer表作为示例。

Scenario: Retrieve name of the customers in descending order.

场景 :按降序检索客户名称。

Query:

查询

SELECT CutomerName FROM Customer ORDER BY CustomerName desc;

Output:

输出:

CustomerName
John
Annie
Amit
null
顾客姓名
约翰
安妮
阿米特
空值

SQL顺序按多个升序降序 (SQL Order By Multiple Ascending Descending)

Scenario: Retrieve customer data based on CustomerGender in ascending and CustomerName in descending order.

场景 :基于CustomerGender升序和CustomerName降序检索客户数据。

Query:

查询

SELECT * FROM Customer ORDER BY CustomerGender ASC, CustomerName desc;

Output:

输出:

CustomerIdCustomerNameCustomerAgeCustomerGender
3Annie35F
1John31M
2Amit25M
4null38M
顾客ID 顾客姓名 客户年龄 客户性别
3 安妮 35 F
1个 约翰 31 中号
2 阿米特 25 中号
4 空值 38 中号

That’s all for a quick roundup on SQL Order By clause.

这就是对SQL Order By子句进行快速汇总的全部内容。

Reference: Oracle Documentation

参考: Oracle文档

翻译自: https://www.journaldev.com/18675/sql-order-by-clause

sql limit 子句

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值