字段内容:0,0,1,1,2,5,8,8,1,2,6,8,4,1
按0-3,4-6,7-9,10-14分组
得出结果
0-3 8
4-6 3
7-10 3
select 0-3" f1,cnt 数量 from (
select count(*) cnt from 表 where 字段>=0 and 字段<=3
) a
union all
select "4-6" f1,cnt 数量 from (
select count(*) cnt from 表 where 字段>=4 and 字段<=6
)b
union all
select "7-10" f1,cnt 数量 from (
select count(*) cnt from 表 where 字段>=7 and 字段<=10
) c
可以,先用case...when无法把不同区间转成对应的数或标记,然后按这个字段值分组