现在需要查询一组数据,是对一列字段(column01)的数据分范围查询后分组排序:
select (case
when [column01] >0 AND [column01]<= 500 THEN 1
when [column01] >500 AND [column01]<= 1000 THEN 2
when [column01] >1000 AND [column01]<= 5000 THEN 3
when [column01] >5000 AND [column01]<= 20000 THEN 4
when [column01] >20000 AND [column01]<= 40000 THEN 5
else 0
end) f,
count(1) cnt from your_table WHERE [column01] > 0 group by
(case
when [column01] >0 AND [column01]<= 500 THEN 1
when [column01] >500 AND [column01]<= 1000 THEN 2
when [column01] >1000 AND [column01]<= 5000 THEN 3
when [column01] >5000 AND [column01]<= 20000 THEN 4
when [column01] >20000 AND [column01]<= 40000 THEN 5
else 0
end)