2013-08-27 48 views
0

當前我在做一個項目,我需要生成從表中提取的報表。 表按如下如何用不同的分組標準求和多個列

CURRENCY_A AMOUNT_A CURRENCY_B AMOUNT_B CURRENCY_C AMOUNT_C

我的預期是由貨幣 USD(AMOUNT_A + AMOUNT_B + AMOUNT_C)基團的總計總和:
EURO:
磅數:

是否有可能單獨在oracle中執行此輸出?

+0

如果您規範化表 – zxc

+0

感謝,但問題是我不能改變表結構已經 – user2720648

+0

@ user2720648你爲什麼要刪除您發佈數據的樣本,它會更容易?而且,如果你提供了期望的輸出,它會更好。 –

回答

0
SELECT currency, SUM(total1) AS total FROM 
(
SELECT currency_a AS currency, SUM(a_amount) AS total1 FROM table1 
GROUP BY currency_a 
UNION ALL 
SELECT currency_b, SUM(b_amount) AS total2 FROM table1 
GROUP BY currency_b 
UNION ALL 
SELECT currency_c, SUM(c_amount) AS total2 FROM table1 
GROUP BY currency_c 
) T 
GROUP BY currency 
相關問題