楼主的意思是不为0的有多少,全部的又有多少吧 select leibie,sum(case when shifei<>0 then 1 else 0 end) shi,count(*) all from 表 group by leibie
1:好象楼主说的与结果不符。 按照leibie分类,统计为0的有多少,全部的有多少 2: select leibie,sum(case when shifei = 0 then 1 else 0 end) as shi, count(*) as all from 表 group by leibie 3: select distinct leibie,(select count(*) from 表 where leibie = a.leibie and shifei = 0) as shi, (select sum(1) from 表 where leibie = a.leibie ) as all from 表 a
select leibie,sum(shifei) shi,count(*) all from 表 group by leibie
select leibie,sum(iif(shifei=0,1,0)) shi,count(*) all from 表 group by leibie
同意 select leibie,sum(iif(shifei=0,1,0)) shi,count(*) all from 表 group by leibie
就是按照leibie分类,统计为0的有多少,全部的有多少,应该是这样的: select leibie,sum(iif(shifei=0,1,0)) as shi,count(*) as all from 表名 group by leibie
select leibie,sum(case when shifei<>0 then 1 else 0 end) shi,count(*) all
from 表 group by leibie
按照leibie分类,统计为0的有多少,全部的有多少
2: select leibie,sum(case when shifei = 0 then 1 else 0 end) as shi,
count(*) as all from 表 group by leibie
3: select distinct leibie,(select count(*) from 表 where leibie = a.leibie and shifei = 0) as shi,
(select sum(1) from 表 where leibie = a.leibie ) as all from 表 a
select leibie,sum(iif(shifei=0,1,0)) shi,count(*) all from 表 group by leibie
select leibie,sum(iif(shifei=0,1,0)) as shi,count(*) as all from 表名 group by leibie