复杂的oracle分组统计
oracle如何对表里某个字段进行区间分组统计?即分组的字段在某区间为一组,如字段在1~5一组,5~10一组等,这种情况该如何用group by呢?
------解决方案--------------------可以写个function f(x integer) return integer;
group by f(x)
也可以直接用group by (case when x between 1 and 5 then 1 when x between 6 and 10 then 2 else 3 end)
或者group by decode(x,1,1,2,1,...,5,1,6,2,7,2,...,10,2,3)
------解决方案--------------------sign(value-1)+sign(value-5)+sign(value-10)