zoukankan      html  css  js  c++  java
  • ORACLE自定义顺序排序-转

    ORACLE可以借助DECODE函数,自定义顺序排序:

    复制代码
    select * from (
        select 'Nick' as item from dual
        union all
        select 'Viki' as item from dual
        union all
        select 'Glen' as item from dual
        union all
        select 'Robin' as item from dual
        union all
        select 'Total' as item from dual
    ) pre_tab
    order by decode(item, 'Viki', 1, 'Glen', 2, 'Robin', 3, 'Nick', 4, 'Total', 99);
    复制代码

    另外,在Report开发中,常需要将Total放最后,其它项则按其它排序方式(一般按正常的升序),可看作同一列有两种排序方式,那么可以这样:

    复制代码
    select * from (
        select 'Nick' as item from dual
        union all
        select 'Viki' as item from dual
        union all
        select 'Glen' as item from dual
        union all
        select 'Robin' as item from dual
        union all
        select 'Total' as item from dual
    ) pre_tab
    order by decode(item, 'Total', 2, 1), item;
    复制代码
  • 相关阅读:
    Gin+Gorm小项目
    python实现监控信息收集
    Vue引入Stylus
    Go搭建一个Web服务器
    saltstack高效运维
    04-01 Django之模板层
    03-01 Django之视图层
    02-01 Django之路由层
    HTTP协议
    01-01 Web应用
  • 原文地址:https://www.cnblogs.com/zhangzhu/p/5508743.html
Copyright © 2011-2022 走看看