我有如下数据
A B
= 1
= 2
!= 3
= 4
!= 5
我需要将这些放入一个列中,以便所有 '!=' 都低于“=”数据,并且只有在列 A 中存在带有 '!=' 的行时,才将 '!=' 作为虚拟行
1
2
4
!=
3
5
用于union all
获取行中所需的所有值。添加一列以指定展示位置。该列的顺序:
select value
from (select cast(B as varchar2(255)) as value, 1 as which
from t
where A <> '!='
union all
select '!=', 2 from dual
union all
select cast(B as varchar2(255)) , 3
from t
where A = '!='
) s
order by which;
编辑:
对于修订版:
select value
from ((select cast(B as varchar2(255)) as value, 1 as which
from t
where A <> '!='
) union all
(select '!=', 2 from dual where exists (select 1 from t where A = '!=')
) union all
(select cast(B as varchar2(255)), 3
from t
where A = '!='
)
) s
order by which;