oracle 累加功能,累加百分比


最近做数据分析,需要用到累加功能,发现强大的oracle还真有,用over(order by field)

例子:

数据表中最后一列就是累加的效果

累加sql:

select t.acc_pedal_pos,count(*) num,sum(count(*)) over(order by t.acc_pedal_pos) accu_sum from  GT1117CARDATA t where t.acc_pedal_pos>0 group by t.acc_pedal_pos  order by t.acc_pedal_pos

根据累计求和,进一步求占总和的百分比

sql:

--计算累计百分比,先求列和,然后嵌套求百分比
select t1.*,round(t1.accu_sum/t2.allsum*100,2)||'%' from (select t.acc_pedal_pos,
       count(*) num,
       sum(count(*)) over(order by t.acc_pedal_pos) accu_sum
  from GT1117CARDATA t
 where t.acc_pedal_pos > 0
 group by t.acc_pedal_pos
 order by t.acc_pedal_pos)t1,(select count(acc_pedal_pos) allsum from GT1117CARDATA where acc_pedal_pos>0) t2

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM