2015-07-21 137 views
1

我需要生成兩個不同列的總和。獲取兩個不同的列總計

我的查詢看起來像這樣

SELECT 0 AS OTHER_AMT, ABS([MISC AMT]*100) AS MISC_AMT FROM ESCHEATMENT_FINAL WHERE [TRAN DT] < '6/30/2012' AND [MISC AMT]<>0 

UNION ALL 

SELECT ABS([DEP AMT]*100+[INT AMT]*100) AS OTHER_AMT, 0 AS MISC_AMT FROM [CCC_Escheatment].[dbo].[ESCHEATMENT_FINAL] WHERE [TRAN DT] < '6/30/2014' AND [DEP AMT]<>0 

我需要一個總額加起來兩個MISC_AMT和OTHER_AMT。我該怎麼去做這件事

回答

2
select sum(other_amt) + sum(misc_amt) from (
    SELECT 0 AS OTHER_AMT, ABS([MISC AMT]*100) AS MISC_AMT FROM ESCHEATMENT_FINAL WHERE [TRAN DT] < '6/30/2012' AND [MISC AMT]<>0 

    UNION ALL 

    SELECT ABS([DEP AMT]*100+[INT AMT]*100) AS OTHER_AMT, 0 AS MISC_AMT FROM [CCC_Escheatment].[dbo].[ESCHEATMENT_FINAL] WHERE [TRAN DT] < '6/30/2014' AND [DEP AMT]<>0 
) 
+0

謝謝,我明白了! – chachi

相關問題