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
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
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
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)
union all
select id='b',记录数=count(*) from table where b=1
union all
select id='d',记录数=count(*) from table where d=1
b=Sum(case b when 1 then 1 else 0),
c=Sum(case c when 1 then 1 else 0)
from tb
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
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)