首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

在sql分类汇总语句下,加一个子汇总统计

2012-11-11 
在sql分类汇总语句上,加一个子汇总统计原sql:select count (*) as number,paramvalue.param_valuefrom par

在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 ...

热点排行