我的表是这样的:ORDER BY语句 - 排序由多个列
A B C
-----------------------
111 3
777
333 1
555 2
333
777 4
888 5
所以,我必须声明令“经B顺序”和我有结果是这样的:
A B C
----------------------
333 1
555 2
111 3
777 4
888 5
777
333
但是,我能做些什么来得到这个排序:
A B C
-----------------------
333 1
333
555 2
111 3
777 4
777
888 5
如果列C时不为空,我应该排wher后把此行e A = C
谢谢!
所以,在这种情况下:
with a(a,b,c) as (select 111,4, null from dual union all
select null,null,777 from dual union all
select 333,1,null from dual union all
select 555,2, null from dual union all
select null,null, 333 from dual union all
select 777, 4, null from dual union all
select 444,null, 333 from dual union all
select 888, 5, null from dual union all
select null,null,777 from dual)
select a.*
from a
order by last_value(b ignore nulls)
over (partition by CASE when b is null then c else a end order by b), b nulls last
我有输出(C 777是A 111后,因为B值是相同= 4):
A B C
--------------------
333 1
444 333
333
555 2
777 4
111 4
777
777
888 5
但我要得到这样的:
A B C
--------------------
333 1
444 333
333
555 2
777 4
777
777
111 4
888 5
你可以有A和C不为空两行? – Aleksej
是的,我可以有这样的行 – user2783755
@ user2783755,请检查我的答案,有2个变种 –