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