本帖最后由 suixufeng 于 2011-11-14 10:17:19 编辑

解决方案 »

  1.   

    sum(case when.... then 1 else 0 end)
      

  2.   

    select ...,sum(case when 你的条件 then 1 else 0 end) [count]
    from ...
      

  3.   

    或用count (CASE WHEN 條件 THEN 列 end) as [count]
      

  4.   


    select count (*) as number,paramvalue.param_value,cnt=sum(case when 条件 then 1 else 0 end) from paramvalue join project_fj on danjia between cast(left(param_value ,charindex('-',param_value )-1) as int) and cast(right(param_value ,len(param_value )-charindex('-',param_value )) as int) where paramvalue.paramclass_id=12 group by paramvalue.param_value
      

  5.   

    sum(case when 条件 then 1 else 0 end) as cnt