select (Select sum([BaoMingRenShu])  from [FBaoMingRenShu] as x where a.[ID] = x.[TuanDuiID]) as BaoMingRenShu
 From FFaTuanJiHua AS
 a  WHERE a.[ID] > 0 and (a.[XianLuID]
 in (433)) 
查询结果是:
    BaoMingRenShu
1    6
2    12
3    20
我想把报名人数(BaoMingRenShu)再加起来,怎么实现

解决方案 »

  1.   

    最简单的就是select sum(BaoMingRenShu) as BaoMingRenShu
    from(
    select (Select sum([BaoMingRenShu])  from [FBaoMingRenShu] as x where a.[ID] = x.[TuanDuiID]) as BaoMingRenShu 
    From FFaTuanJiHua AS 
    a  WHERE a.[ID] > 0 and (a.[XianLuID] 
    in (433)) 
    ) t
      

  2.   

    select cast(a.id as varchar) id , sum(x.BaoMingRenShu) BaoMingRenShu from FFaTuanJiHua a , FBaoMingRenShu x where a.ID > 0 and a.XianLuID = 433 and a.id = x.TuanDuiID group by cast(a.id as varchar)
    union all
    select '合计' , sum(x.BaoMingRenShu) BaoMingRenShu from FFaTuanJiHua a , FBaoMingRenShu x where a.ID > 0 and a.XianLuID = 433 and a.id = x.TuanDuiID
      

  3.   

    select TuanDuiID,sum(BaoMingRenShu) BaoMingRenShu
    from FBaoMingRenShu a inner join FFaTuanJiHua b
    on a.TuanDuiID=b.ID
    where b.ID>0 and b.XianLuID=433
    group by TuanDuiID
    with rollup