SQL 整型类弄的数据按区间查找
一表中有1字段类型为int 型,值为0-9999不等,现为了按区间如“ 0-10,10-20....等统计该区间内的总数,根据此需要求SQL如下:
select Interval, count(*) num from (
select case when keyword_density =0 then “区间一"
when keyword_density>0 and keyword_density<=1 then "区间二"
when keyword_density>1 and keyword_density<=2 then "区间三"
when keyword_density>2 and keyword_density<=8 then "区间四"
when keyword_density>8 and keyword_density<=15 then "区间五"
when keyword_density>15 and keyword_density<=20 then " 区间六"
else "其它区间" end as Interval from keyword_density ) as temp
group by Interval
order by Interval