我有一个选择命令的结果集:
1 Null Null Null
1 1 Null Null
1 1 Null 1
1 1 1 Null
但我需要像这样重新排序:
1 Null Null Null
1 1 Null Null
1 1 1 Null
1 1 Null 1
我怎样才能做到这一点?
选择语句:
select K,
Null As M,
Null As T1,
Null As T2,
SUM(debit) SumDebit
from h
join i On h.HdrId = i.HdrIdRef
Group by K
Union
select K,
M,
Null As T1,
Null As T2,
SUM(debit) SumDebit
from h
join i On h.HdrId = i.HdrIdRef
Group by K,M
Union
Select *
From
( select K,
M,
T1,
Null As T2,
SUM(debit) SumDebit
from h
join i On h.HdrId = i.HdrIdRef
Group by K,M,T1
) A
Where A.T1 Is Not Null
Union
Select *
From
( select K,
M,
T1,
T2,
SUM(debit) SumDebit
from h
join i On h.HdrId = i.HdrIdRef
Group by K,M,T1,T2
) A
Where A.T2 Is Not Null
Order By K, M, T1, T2