2013-07-04 106 views
0

我想告訴這個查詢,因爲只有一個單元的總和,但使用UNION這裏的結果顯示爲這樣的合計金額與SUM計算嵌套查詢

500 
    1000 

一列,但我想說明的總和這個記錄(1500)

這是我的查詢:

select sum(MAL_TASWYAHESAB.MADINMONY) as'Total Sum' from MAL_TASWYAHESAB 
union 
select sum(MAL_AMRSARF_OHAD.MONY) as'Total Sum' from MAL_AMRSARF_OHAD 

回答

1

試試這個方法:

select (select sum(MAL_TASWYAHESAB.MADINMONY) from MAL_TASWYAHESAB) 
+ 
(select sum(MAL_AMRSARF_OHAD.MONY) from MAL_AMRSARF_OHAD) as 'Total Sum' 
0
SELECT SUM(TotalSum) AS Total 
FROM 
(
    select MAL_TASWYAHESAB.MADINMONY as 'TotalSum' from MAL_TASWYAHESAB 
    union 
    select MAL_AMRSARF_OHAD.MONY     from MAL_AMRSARF_OHAD 
) AS t 
0
select sum(MADINMONY) as'Total Sum' 
from (
    select MAL_TASWYAHESAB.MADINMONY 
    from MAL_TASWYAHESAB 
    union MAL_AMRSARF_OHAD.MONY 
    from MAL_AMRSARF_OHAD 
) AS X 
0
SELECT SUM(MADINMONY) as'Total Sum' 
FROM (
    SELECT MAL_TASWYAHESAB.MADINMONY 
    FROM MAL_TASWYAHESAB 
    UNION MAL_AMRSARF_OHAD.MONY 
    FROM MAL_AMRSARF_OHAD 
) AS a;