2011-04-08 66 views
0

我的表名在MS接取 場AE ID,交易,金額CAPCON,computition與空的MS Access

我的查詢是

Select distinct(CapCon.ID), 
(Select sum(amount) from CapCon as c 
    where c.id=CapCon.id 
    and transaction='Deposite') - 
(Select sum(amount) from CapCon as c 
    where c.id=CapCon.id and transaction='Withdrawal') 
as [Capital Contribution] from CapCOn 

中頻沒有取款的交易,沒有在[出資]輸出相應的ID

+1

嘿,Ryan,僅供將來參考,您可以通過縮進4個空格或在其周圍添加反斜槓來格式化代碼。您提出的問題越容易閱讀,您就越有可能得到答案。 :) – 2011-04-08 01:32:21

回答

2

您需要在WHERE子句中檢查null:

Select distinct(CapCon.ID), 
    (Select sum(amount) from CapCon as c 
    where c.id=CapCon.id 
    and transaction='Deposite') - 
    (Select sum(amount) from CapCon as c 
    where c.id=CapCon.id 
    and transaction='Withdrawal' 
    and transaction is not null) 
as [Capital Contribution] from CapCOn 
+0

請在回答時花時間格式化代碼。 – 2011-04-08 01:35:18