我的表是這樣的: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個變種 –