Select AID,AA,IsNull(sum(IsNull(BA,0)),0)
From A Left join B on AID = B_AID

解决方案 »

  1.   

    select a.aid,a.aa,isnull(b.b,0) from 表A a left join (select b_AID,sum(BA) BA from 表B where b_AID is not null group by b_AID) b
     on b.B_AID=a.AID
      

  2.   

    select *,isnull((select sum(BA) from 表b where b_AID=表A.AID),0) ba from 表A
      

  3.   

    你给的表有些问题吧?
    表A的AID为字符,表B的b_AID为数字,所以如果按你的表,应该如下写select a.*,isnull(sum(b.ba),0) as ba
    from 表A a left join 表B b
    on right(a.AID,len(a.AID)-1)=b.b_AID
    group by a.AID,a.AA
      

  4.   

    下面是根据你给出的表所做的数据测试:--创建数据测试环境
    declare @表A table(AID varchar(2),AA int)
    insert into @表a
    select 'A1',30
    union all select 'A2',40
    union all select 'A3',50declare @表B table(BID int,BA int,b_AID int)
    insert into @表B
    select 1,20,1
    union all select 2,3,1
    union all select 3,4,2
    union all select 4,5,null
    union all select 5,6,2
    union all select 6,10,null--得到你要求的结果
    select a.*,isnull(sum(b.ba),0) as ba
    from @表A a left join @表B b
    on right(a.AID,len(a.AID)-1)=b.b_AID
    group by a.AID,a.AA
      

  5.   

    Select AID,AA,IsNull(sum(IsNull(BA,0)),0)
    From A Left join B on AID = B_AID
    group by AID,AA
      

  6.   

    上面语句的执行结果为:AID  AA          ba          
    ---- ----------- ----------- 
    A1   30          23
    A2   40          10
    A3   50          0(所影响的行数为 3 行)
      

  7.   

    http://expert.csdn.net/Expert/topic/2082/2082186.xml?temp=.6836817http://expert.csdn.net/Expert/topic/2082/2082300.xml?temp=.6041834