我有2個以下的表格,我必須寫一個查詢來顯示通過信用卡接收的總金額的總和並檢查。將別名分別命名爲'total_credit'和'total_cheque'。Oracle查詢顯示來自同一列的2個總和字段,並根據不同表格中的不同字段條件計算出來
table_payment
ID(PK)
USER_ID
量
transaction_type_id(FK)
table_transaction_type
ID(PK)
型
預期輸出:
total_credit| total_cheque
Value a | Value B
我試過下面的查詢,但我在不同的行
select sum(case when tt.type = 'Credit Card' then pt.amount end) as
"total_credit", sum (case when tt.type = 'Cheque' then pt.amount end)
as "total_cheque" from payment pt join transaction_type tt on
pt.transaction_type_id = tt.id group by tt.type
Actual_Output獲取值:
total_credit| total_cheque
Value A |
| Value B
不知道如何在第一行獲得B值A值一起,請指教。
看起來你決定改變表名('table_cheque'不是表在他原來的問題) – phroureo
@phroureo感謝您的評論,更正! –