2011-04-08 49 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