zoukankan      html  css  js  c++  java
  • ORACLE 按照指定顺序排序输出某些字段

    摘自:

    https://www.cnblogs.com/nick-huang/p/4076273.html

    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;

    附 一条: 添加字段,排序 可以这样(比如下面的 年份 nf)

    order by nf, decode(dq,'贵阳',1,'遵义',2,'六盘水',3,'安顺',4,'都匀',5,'凯里',6,'铜仁',7,'兴义',8,'毕节',8,'贵安',10,'黔江',11,'送周边',12)
  • 相关阅读:
    pip 安装依赖 requirements.txt
    TCP三次握手四次挥手详细理解附面试题
    装饰器修复技术
    BBS(第一篇)
    Auth模块
    Django--中间件
    cookie和session
    创建多对多表关系的三种方式
    批量插入数据,自定义分页器
    Django--几个重要方法优化(面试重点)
  • 原文地址:https://www.cnblogs.com/rdchen/p/13756047.html
Copyright © 2011-2022 走看看