select a.code,count(*)
from a,b
where a.id = b.aid
group a.code

解决方案 »

  1.   

    select a.code,count(*) from a,b where a.id=b.aid group by a.code
      

  2.   

    select code,sum(aid) from a inner join b on b.id=a.id group by id,code
      

  3.   

    select a.code,
           count(*) as [count]
    from a a
    left join b b
    on a.id=b.aid
    group by a.code
      

  4.   

    to xluzhong(打麻将一缺三,咋办?)没有C 统计结果却是1.......
      

  5.   

    select a.code,
          sum(case when b.aid is null then 0 else 1 end) as [Count]
    from a a
    left join b b
    on a.id=b.aid
    group by a.code
      

  6.   

    select a.code,sum( case cast(a.id as varchar) when b.aid then 1 else 0 end) 
     from a,b group by a.code
    這才對了﹗﹗
    哈哈﹗﹗
      

  7.   

    select a.code,sum( case cast(a.id as varchar) when b.aid then 1 else 0 end) as [count]  from a,b group by a.code  
    這樣就和你想要的結果一樣了﹗﹗
      

  8.   

    select a.code,
        sum(case when b.aid is null then 0 else 1 end) as b
    from a 
    left join b 
    on a.id=b.aid
    group by a.code
      

  9.   

    to  Hopewell_Go(一定好起來) 
    还是不一样,你自己测一下吧