疑难点一是要分类统计的区间是一个字符串,例如“0-60” ,还有就是这个分类不是固定分成几类,区间值也不确定
常量表param:
id param_value paramclass_id
1 0-60 11
2 60-100 11
3 100-300 11
要被统计的表room
id mianji
1 59
2 40
3 236
最后想要统计的效果
count param_value
2 0-60
0 60-100
1 100-300
解决的SQL语句:
select param_value ,count(*) as number from paramvalue join project_fj on mianji 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='11' group by paramvalue.param_value