oracle order by 排序

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 distinctgroup by时,order by 不能使用select之外的列;
select job, avg(sal) "Average Salary" 
    from emp 
    group by job 
    order by "Average Salary" DESC;

猜你喜欢

转载自www.cnblogs.com/hyang0/p/10587003.html