想通过SQL语句实现如下结果,
数值区间 [-30, -25) [-25, -20) [-20, -15) [-15, -10) [-10, -5)
求和数值 77.48777008 376.756355286 453.50503993 543.089648724 127.003311157假设数据表Table如下
A     B
-29   15.2323754
-23   1.2443533
-27   15.234324
-7    10.876234
-14   5.22836734
-21   115.2323124
-5    152.212334
.......请大侠帮忙指点下如何写出sql语句实现按照A的数据区间分组统计求和?谢谢OracleSQLC#

解决方案 »

  1.   

    select sum(result1),sum(result2),sum(result3),sum(result4),sum(result5) from(
    select (case when num1>=-30 and num1<-25 then (num2) end) result1,
    (case when num1>=-25 and num1<-20 then (num2) end) result2,
    (case when num1>=-20 and num1<-15 then (num2) end) result3,
    (case when num1>=-15 and num1<-10 then (num2) end) result4,
    (case when num1>=-10 and num1<-5 then (num2) end) result5
     from test2)t