ORDER BY 5 DESC 是什么意思?

发布于 2024-12-13 11:16:03 字数 703 浏览 0 评论 0原文

SELECT Departamentos.Nome_Dep,  
       Funcionarios.Nome AS Funcionario,
       Funcionarios.Salario,
       AVG(Funcionarios.Salario) OVER(PARTITION BY Departamentos.Nome_Dep) "Média por Departamento"
       Salario - AVG(Funcionarios.Salario) OVER(PARTITION BY Departamentos.Nome_Dep) "Diferença de Salário"   FROM Funcionarios
INNER JOIN Departamentos
    ON Funcionarios.ID_Dep = Departamentos.ID
ORDER BY 5 DESC

Order By 5 让我很失望。我从来没有遇到过这样的事情。按 [列名] 排序是的,但是按 [数字] 排序,以前从未见过。我从一篇文章中摘录了这一点。

注意:这是 T-SQL。

来源:SQL Server 2005 中的窗口函数、2008、2012

SELECT Departamentos.Nome_Dep,  
       Funcionarios.Nome AS Funcionario,
       Funcionarios.Salario,
       AVG(Funcionarios.Salario) OVER(PARTITION BY Departamentos.Nome_Dep) "Média por Departamento"
       Salario - AVG(Funcionarios.Salario) OVER(PARTITION BY Departamentos.Nome_Dep) "Diferença de Salário"   FROM Funcionarios
INNER JOIN Departamentos
    ON Funcionarios.ID_Dep = Departamentos.ID
ORDER BY 5 DESC

The Order By 5 is throwing me off. I've never anything like it. Order By [colunmname] yes, but Order By [number], never seen before. I pulled this off an article.

Note: This is T-SQL.

Source: Window Functions in SQL Server 2005, 2008, 2012

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

嘿看小鸭子会跑 2024-12-20 11:16:04

这将按此 SELECT 语句中的第 5 个字段进行排序

This will order by the 5th field in this SELECT statement

淡淡の花香 2024-12-20 11:16:04

按结果集中的第 5 列排序。

Order by the 5th column in the result set.

苏璃陌 2024-12-20 11:16:04

该数字表示选择列表中列的索引。

来源:http://mattberseth.com/blog/2007/05/quick_tip_order_by_1_descendin.html

The number represents the index of the column within your select list.

Source: http://mattberseth.com/blog/2007/05/quick_tip_order_by_1_descendin.html

忘东忘西忘不掉你 2024-12-20 11:16:04

按结果集中第五列降序排序。

Order by fifth column in the result set descending.

浅忆流年 2024-12-20 11:16:04

这是按相对位置排序

您可以使用 SQL ORDER BY 子句按结果集中的相对位置进行排序,其中结果集中的第一个字段为 1。下一个字段为 2,依此类推。
在本例中,按结果集中的第 5 个字段排序。

浏览 http://www.techonthenet.com/sql/order_by.php
关于sql排序依据。

It is the SORTING BY RELATIVE POSITION.

You can use the SQL ORDER BY clause to sort by relative position in the result set, where the first field in the result set is 1. The next field is 2, and so on.
Here in this case Order by 5th field in the result set.

Go through http://www.techonthenet.com/sql/order_by.php
about sql order by.

青衫负雪 2024-12-20 11:16:04

当类似的列名已成为计算输出字段时很有用,

在以下示例中,如果说“order by numberofVioation”,则会令人困惑,因为该列名刚刚成为查询输出 SUM 字段(同一旧列的名称) data)

因此它在计算输出字段中变得有用

示例:

原始字段:

名称|类型|风险等级|日期|结果|违规行为|

/* 现在为每种类型添加额外的违规总和,请注意 'order by 2 desc' 指的是按第二个查询列排序,即从 hi 到 low */

select Type, sum(numberOfViolations) as numberOfViolations
来自餐厅表
按类型分组
按 2 描述排序

Useful when a similar column name has become a calcuated output field,

In the following example, it would be confusing if say 'order by numberofVioation' as this column name has just become the name of a query output SUM field (of the same old column data)

So it become useful in calculated output field

Example:

Original fields:

name| Type| RiskLevel| Date| results| violations|

/* now add an extra Sum of Violation for each type, pls note 'order by 2 desc' refers to order by the 2nd queried column, ie hi to low */

select Type, sum(numberOfViolations) as numberOfViolations
from restaurantsTable
group by Type
order by 2 desc

如果没结果 2024-12-20 11:16:04

按结果集中的第 5 个字段排序。

Order by 5th field in the result set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文