2014-03-03 45 views
0

我需要總價值從多個表。如何從多個表格總價格總和?

這是SQL Server查詢

Select 
sum(Tbl_StartupBanner.Price + Tbl_SignInBanner.Price + Tbl_SignOutBanner.Price) as Total 
from Tbl_StartupBanner,Tbl_SignInBanner,Tbl_SignOutBanner 
 
Tbl_StartupBanner - Price Value - 1 
Tbl_SignInBanner - Price Value - 1 
Tbl_SignOutBanner - Price Value is None .. There is No record in This table ... 

但我需要總數爲:2

+0

目前還不清楚你問 –

+1

我不明白你的問題,你的問題dy使用Select sum(Tbl_StartupBanner.Price + Tbl_SignInBanner.Price + Tbl_SignOutBanner.Price)。首先,如果Tbl_StartupBanner - Price Value - 1 Tbl_SignInBanner - Price Value - 1,那麼結果將爲2.其次,在這種情況下不會發生聚合,因此在此處不必強制總和 –

+0

您當前查詢的輸出結果是... – pankeel

回答

0
Select 
ISNULL(t1.Price, 0) + ISNULL(t2.Price, 0) + ISNULL(t3.Price, 0) as Total 
from Tbl_StartupBanner t1 
LEFT JOIN Tbl_SignInBanner t2 ON t1.MatchCol = t2.MatchCol 
LEFT JOIN Tbl_SignOutBanner t3 ON t1.MatchCol = t2.MatchCol 
0

試試這個

SELECT TableA.Column1 + TableB.Column2 FROM TableA 
LEFT JOIN TableB ON TableA.MatchingColumn = TableB.MatchingColumn