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 表
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
SELECT COUNT(C1) FROM 表 where c1='1' union all SELECT COUNT(C1) FROM 表 where c2='1'
sum(case when c2 = 1 then 1 else 0 end) as c2的数量
from 表
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
union all
SELECT COUNT(C1) FROM 表 where c2='1'