select SN,
[count(b)] = (select count(1) from b where SN = a.SN), 
[count(c)] = (select count(1) from c where SN = a.SN)
from a

解决方案 »

  1.   

    对 或者用 sum(case when b.sn is null then 0 else 1 end) as [count(b)]
      

  2.   


    declare @tablea table(sn int)
    insert @tablea values(1)
    insert @tablea values(2)
    insert @tablea values(3)declare @tableb table(sn int ,detail char(5))
    insert @tableb values(1,'fdf')
    insert @tableb values(1,'342')
    insert @tableb values(2,'ewrew')declare @tablec table(sn int ,detail char(5))
    insert @tablec values(2,'dfdf')
    insert @tablec values(3,'dfd')
    insert @tablec values(3,'fdds')
    select a.sn,
    (select count(*) from @tableb where a.sn = sn) [count(b)],
    (select count(*) from @tablec where a.sn = sn) [count(c)]
    from @tablea a/*
    sn          count(b)    count(c)    
    ----------- ----------- ----------- 
    1           2           0
    2           1           1
    3           0           2(所影响的行数为 3 行)
    */
      

  3.   

    各位大佬都比较忙,看看标题头好吗?是Pradox,不支持CASE的。
      

  4.   

    select SN,[count(b)] = (select count(1) from b where SN = a.SN), [count(c)] = (select count(1) from c where SN = a.SN)
    from a
      

  5.   

    select SN,
    [count(b)] = (select count(1) from b where SN = a.SN), 
    [count(c)] = (select count(1) from c where SN = a.SN)
    from a-- 卡看可以用吗?我也不知道。sql是可以。
      

  6.   

    原来如此 paradox 支不支持 isnull?
    Select a.sn,(count(*) -sum(isnull(b.sn,1))) sn_b,(count(*) -sum(isnull(c.sn,1))) sn_c
    from a left join b on a.sn=b.sn
           left join c on a.sn=c.sn
    group by a.sn
      

  7.   

    谢谢各位大佬。select SN,
    (select count(1) from b where SN = a.SN), 
    (select count(1) from c where SN = a.SN)
    from a到是可以通过,但统计出来全是0。另外: pradox 是不支持isnull的.
      

  8.   

    不是吧,都有人说:{zjcxc(邹建) 哥哥好厉害
    =====================
    学习~~}呵呵,我也姓邹。
      

  9.   

    select SN,
    (select count(*) from b where SN = a.SN), 
    (select count(*) from c where SN = a.SN)
    from aparadox不支持count(1)
      

  10.   

    select SN,
    (select count(*) from b where SN = a.SN), 
    (select count(*) from c where SN = a.SN)
    from a是可以通过,但统计出来全是0。
      

  11.   

    Select a.sn,count(b.sn), count(c.sn)
    from a left join b on a.sn=b.sn
           left join c on a.sn=c.sn
    group by a.sn  没有问题根据你的数据结果应该为sn                                  
    ----------- ----------- ----------- 
    1           2           0
    2           1           1
    3           0           2
      

  12.   

    对不起,错了,应该是:
    怎么得出
    SN    count(b) count(c)
    --------------------
    1     2        0
    2     1        1
    3     0        2