select leibie,sum(case when shifei=0 then 1 else 0 end) shi,count(*) all from 表 group by leibie

解决方案 »

  1.   

    我现在用的是ACCESS,不能使用case when...then,怎么办?
      

  2.   

    楼主的意思是不为0的有多少,全部的又有多少吧
    select leibie,sum(case when shifei<>0 then 1 else 0 end) shi,count(*) all 
    from 表 group by leibie
      

  3.   

    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
      

  4.   

    select leibie,sum(shifei) shi,count(*) all from 表 group by leibie
      

  5.   

    select leibie,sum(iif(shifei=0,1,0)) shi,count(*) all from 表 group by leibie
      

  6.   

    同意
    select leibie,sum(iif(shifei=0,1,0)) shi,count(*) all from 表 group by leibie
      

  7.   

    就是按照leibie分类,统计为0的有多少,全部的有多少,应该是这样的:
    select leibie,sum(iif(shifei=0,1,0)) as shi,count(*) as all from 表名 group by leibie