Select NO as 种类,sum(IsNull(value,0)) as 总和,count(*) as 总记录数,sum(case when value = 0 then 1 else 0 end) as 为零的记录数,sum(case when value is null then 1 else 0 end) as 为空的记录数 
from 有一个表 
group by NO

解决方案 »

  1.   

    select NO
      ,sum(isNULL(value,0))总和
      ,count(*) 总记录数
      ,sum(case when value=0 then 1 else 0 end ) 为零的记录数
      ,sum(case when value is null then 1 else 0 end ) 为空的记录数
    from 表
    group by NO
      

  2.   

    谢谢 txlicenhe(不做技术高手) 大哥马上给你结帐!
      

  3.   

    select NO,SUM(VALUE),COUNT(VALUE),SUM(CASE WHEN VALUE=0 THEN 1 ELSE 0 END),SUM(CASE WHEN ISNULL(VALUE,0)=0 THEN 1 ELSE 0 END) FROM TABLENAME GROUP BY NO
      

  4.   

    select no,sum(value) 总和,count(*) 总记录数,sum(case when value=0 then 1 end) 为零的记录数,sum(cse when value is null then 1 end) 为空的记录数 from 表 group by no