我知道,我的就是用的代码,问题是这个余额该怎么求,因为有的有项目追加,有的没有
select 金额-管理费 + (select Sum(收入-支出) from type where type.项目编号=account.项目编号) as  余额 from account
如果没有的话where type.项目编号=account.项目编号)就没有匹配的了

解决方案 »

  1.   

    是不是这个意思?type表里可能没有account表里的项目,比如account里这样的:项目编号   金额   管理费
    1           500     100
    2           300     100而type表里可能只有项目1没有项目2,这样的话select子句的结果是null。如果是这个意思,改一下sql语句:
    select 金额-管理费 +(case when (select Sum(收入-支出) from type where type.项目编号=account.项目编号) is null then 0 else (select Sum(收入-支出) from type where type.项目编号=account.项目编号) end) as 余额
    from account
      

  2.   

    可能是由于我的account表的id 是自动编号类型而type id是文本类型吧??
      

  3.   


    是不是这个意思?type表里可能没有account表里的项目,比如account里这样的:项目编号   金额   管理费
    1           500     100
    2           300     100而type表里可能只有项目1没有项目2,这样的话select子句的结果是null。如果是这个意思,改一下sql语句:
    select 金额-管理费 +(case when (select Sum(收入-支出) from type where type.项目编号=account.项目编号) is null then 0 else (select Sum(收入-支出) from type where type.项目编号=account.项目编号) end) as 余额
    from account
    出现
    IErrorInfo.GetDescription 因 E_FAIL(0x80004005) 而失败。
      

  4.   

    select account.*,  hte-glf +(case when (select Sum(sr-zc) from [type] where [type].bianhao=account.bianhao) is null then 0 else (select Sum(sr-zc) from [type] where [type].bianhao=account.bianhao) end) as ye";
      

  5.   

    楼主用的什么数据库阿?mysql?account表的id 是自动编号类型而type id是文本类型,为什么会这样设计阿。
      

  6.   

    type 是保留字>>>>select 金额-管理费 +(case when (select Sum(收入-支出) from [type] where [type].项目编号=account.项目编号) is null then 0 else (select Sum(收入-支出) from [type] where [type].项目编号=account.项目编号) end) as 余额
    from [account]
      

  7.   

    还是这个错
    string myselect = " select [account].*,hte-glf +(case when (select Sum(sr-zc) from [type] where [type].bianhao=account.bianhao) is null then 0 else (select Sum(sr-zc) from [type] where [type].bianhao=account.bianhao) end) as ye from [account]";