0
我有以下Oracle SQL工作正常,但第二個查詢的結果返回第一行而不是第二個。如何通過Oracle中兩個查詢的聯合結果進行排序?
如何維護輸出中的序列,以便第一個查詢結果顯示在第一行,第二個顯示在第二行等等。
的Oracle SQL
select
sum(a.transaction_amount) as transaction_amount,
'Last 30 Days Debit Volume (Current Year)' as sales_volume
from
payment_transaction a,
payment_settlement b
where
a.transaction_status = 'S'
and b.settlement_type = 'D'
and trunc(b.transaction_date) > sysdate - 30
and a.payment_transaction_id = b.payment_transaction_id
union
select
sum(a.transaction_amount) as transaction_amount,
'Last 30 Days Credit Volume (Current Year)' as sales_volume
from
payment_transaction a,
payment_settlement b
where
a.transaction_status = 'S'
and b.settlement_type = 'C'
and trunc(b.transaction_date) > sysdate - 30
and a.payment_transaction_id = b.payment_transaction_id
電流輸出
TRANSACTION_AMOUNT SALES_VOLUME
6272 Last 30 Days Credit Volume (Current Year)
10719 Last 30 Days Debit Volume (Current Year)
期望輸出
TRANSACTION_AMOUNT SALES_VOLUME
10719 Last 30 Days Debit Volume (Current Year)
6272 Last 30 Days Credit Volume (Current Year)
完美!這對我有用:)非常感謝。 – user2325154