比如一个表有a,b,c,d,e 5个字段
返回 a=1,b=1,d=1的记录数分别有多少个。返回一个一行的table

解决方案 »

  1.   

    select id='a',记录数=count(*) from table where a=1
    union all 
    select id='b',记录数=count(*) from table where b=1
    union all 
    select id='d',记录数=count(*) from table where d=1
      

  2.   

    select a=Sum(case a when 1 then 1 else 0),
    b=Sum(case b when 1 then 1 else 0),
    c=Sum(case c when 1 then 1 else 0)
    from tb 
      

  3.   

    select a=Sum(case a when 1 then 1 else 0 end),
    b=Sum(case b when 1 then 1 else 0 end ),
    c=Sum(case c when 1 then 1 else 0 end )
    from tb 
    刚才少个end
      

  4.   

    select 三个统计好的数就行了
    select [a_1]=(select count(*) from tb where a=1),
    [b_1]=(select count(*) from tb where b=1),
    [c_1]=(select count(*) from tb where c=1)