select na,sum(b.bt), count(b1), count(b2), count(b3), count(b4), count(b5)
 from a,b where a.id=b.aid group by a.id,a.na

解决方案 »

  1.   

    select a.aid,a.na,sum(b.bt),count(b1),count(b2),count(b3),count(b4),count(b5) from A join b on a.id=b.aid group by a.aid,a.na
      

  2.   

    TRY:
    select na as 姓名,sum(b.bt) as 总量
      ,count(b1) 合计1
      ,count(b2) 合计2
      ......
    from A left join B on a.id=b.aid
    group by a.na
      

  3.   

    select na,sum(b.bt), count(b1), count(b2), count(b3), count(b4), count(b5)
     from a join b on a.id=b.aid group by a.na
      

  4.   

    不好意思题搞错了,应该是:
    两个表格A,B。
    其中A有id,na,B有id,aid,bt,b俩个表的关系是A.id=B.aid.
    要求用一个查询语句实现下列功能。对B.bt进行sum(),b的值分别有1,2,3,4,5
    显示的数据如:
    na sum(b.bt) count(b1) count(b2) count(b3) count(b4) count(b5)姓名 总量   合计1  合计2   合计3   合计4  合计5谢谢!!
      

  5.   

    而且A.na必须列出,不管合计当中是否有值,没有值用0填补
      

  6.   

    select a.aid,a.na,sum(b.bt),count(b1),count(b2),count(b3),count(b4),count(b5) from A left join b on a.id=b.aid group by a.aid,a.na
      

  7.   

    select a.aid,a.na,sum(b.bt),count(b1),count(b2),count(b3),count(b4),count(b5) from A left join b on a.id=b.aid group by a.aid,a.na
      

  8.   

    select a.aid,a.na,sum(isnull(b.bt,0)),count(b1),count(b2),count(b3),count(b4),count(b5) from A ,B where a.id=b.aid group by a.aid,a.na
      

  9.   

    select na,sum(b.bt), sum(case when b=1 then 1 else 0 end ), sum(case when b=2 then 1 else 0 end ), sum(case when b=3 then 1 else 0), sum(case when b=4 then 1 else 0), sum(case when b=5 then 1 else 0)
     from a,b where a.id=b.aid group by a.id,a.na