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之外的列;
  • order by 只能放最后,不能放集合操作的中间;
  • 集合操作后,不接order by时按第一列进行升序排序(union all除外);
  • 集合操作后的列名为第一个select的内容,order by 只能选第一个select中的内容进行操作
select job, avg(sal) "Average Salary" 
    from emp 
    group by job 
    order by "Average Salary" DESC;

posted on 2019-03-24 09:25  Digital_life  阅读(7176)  评论(0编辑  收藏  举报

导航