ORDER BY 5 DESC 是什么意思?
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。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这将按此 SELECT 语句中的第 5 个字段进行排序
This will order by the 5th field in this SELECT statement
按结果集中的第 5 列排序。
Order by the 5th column in the result set.
该数字表示选择列表中列的索引。
来源: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
按结果集中第五列降序排序。
Order by fifth column in the result set descending.
这是按相对位置排序。
您可以使用 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.
当类似的列名已成为计算输出字段时很有用,
在以下示例中,如果说“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
按结果集中的第 5 个字段排序。
Order by 5th field in the result set.