在sql分类汇总语句上,加一个子汇总统计
原sql:
select count (*) as number,paramvalue.param_value 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
得到的结果:
param_value number
0-60 25
60-80 12
现在我要加一个子汇总count,他在原来number列的基础上,还有自己的子条件strWhere,统计数值count肯定比number小
想得到的结果:
param_value number count
0-60 25 8
60-80 12 10
求高手指点!
------解决方案--------------------
select ...,sum(case when 你的条件 then 1 else 0 end) [count]
from ...