可以。比如 with t as ( select level as rn from dual connect by level <= 5 ), t1 as ( select sum(rn) as rn from t ) select rn from ( select rn,0 as flag from t union all select rn,1 from t1 ) order by flag, rn desc
明细行和总计行,分别是怎么来的? 是 select * from t union all select sum() from .. 这种形式得来的吗?
如果是用union的话,如果要排序字段是B,你给明细加一个字段A赋值2,给总计赋值一个字段A赋值1,最后order by A,B desc
order by 字段 desc nulls last;--按某个字典排序,将空值排在最后 order by 字段 nulls first;--按某个字段排序,将空排在起始 order by decode(字段,'指定值',null,字段)--将指定值放在最后
with t as
( select level as rn from dual connect by level <= 5 ),
t1 as
( select sum(rn) as rn from t )
select rn
from ( select rn,0 as flag from t union all select rn,1 from t1 )
order by flag, rn desc
order by 字段 nulls first;--按某个字段排序,将空排在起始
order by decode(字段,'指定值',null,字段)--将指定值放在最后