select (select count(c1) c1 from ac where c1=1) sumc1 ,(select count(c2)  
from ac where c2=1) sumc2

解决方案 »

  1.   

    select sum(case when c1 = 1 then 1 else 0 end) as c1的数量, 
           sum(case when c2 = 1 then 1 else 0 end) as c2的数量
    from 表
      

  2.   

    declare  @t table(id int,c1 int,c2 int)
    insert @t  select 0,1,0 union all
                     select 1,1,1 union all
                     select 2,0,0 union all
                     select 3,0,0 union all
                     select 4,1,1
    select  count(*) as total1  from @t where c1=1 union all
    select  count(*)  as total2 from @t where c2=1
      

  3.   

    SELECT COUNT(C1) FROM 表 where c1='1'
    union all
    SELECT COUNT(C1) FROM 表 where c2='1'