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;

 

ORACLE 按照指定顺序排序输出某些字段

上一篇:XAMPP Access forbidden! Access to the requested directory is only available from the local network.


下一篇:2020.09 问题总结(Oracle-->MySQL、Maven、JSP-->Thymeleaf、Druid)