Syntax
ORDER BY { column-Name | ColumnPosition | Expression }
[ ASC | DESC ]
[ NULLS FIRST | NULLS LAST ]
[ , column-Name | ColumnPosition | Expression
[ ASC | DESC ]
[ NULLS FIRST | NULLS LAST ]
] *
-
order by
后面可以接列号(数字)、列名、别名、表达式、函数、分组函数 -
order by
对空值的处理,DESC
空值在前,ASC
空值在后; -
order by
子句中可以不含select
中的列; - 当使用
select distinct
或group by
时,order by
不能使用select之外的列;
select job, avg(sal) "Average Salary"
from emp
group by job
order by "Average Salary" DESC;