资源描述:
《oraclesql语句实现累加、累减、累乘、累除》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、oraclesql语句实现累加、累减、累乘、累除收藏在oracle开发过程中经常会遇到累加、减、乘、除的问题。下面对这个做个小的总结--创建测试表createtableaspen(parent_idnumber,part_idnumber,qntynumber);insertintoaspenvalues(1,1,2);insertintoaspenvalues(1,2,3);insertintoaspenvalues(1,3,2);insertintoaspenvalues(1,4,5);insertintoaspenvalu
2、es(2,2,3);insertintoaspenvalues(2,3,5);insertintoaspenvalues(2,4,7);--实现累加selectparent_id,part_id,qnty,sum(qnty)over(partitionbyparent_idorderbypart_id)running_prodfromaspenPARENT_IDPART_IDQNTYRUNNING_PROD------------------------------------------11221235132714512223
3、3235824715--实现累减selectparent_id,part_id,qnty,sum(decode(rn,1,qnty,-qnty))over(partitionbyparent_idorderbypart_id)running_prodfrom(selectparent_id,part_id,qnty,row_number()over(partitionbyparent_idorderbypart_id)rnfromaspen)PARENT_IDPART_IDQNTYRUNNING_PROD------------
4、------------------------------1122123-1132-3145-82233235-2247-9--实现累乘selectparent_id,part_id,exp(sum(ln(qnty))over(partitionbyparent_idorderbypart_id))running_prodfromaspenPARENT_IDPART_IDRUNNING_PROD-------------------------------11212613121460223231524105--实现累除sele
5、ctparent_id,part_id,exp(sum(decode(rn,1,ln(qnty),-ln(qnty)))over(partitionbyparent_idorderbypart_id))running_prodfrom(selectparent_id,part_id,qnty,row_number()over(partitionbyparent_idorderbypart_id)rnfromaspen)PARENT_IDPART_IDRUNNING_PROD----------------------------
6、----11212.66666666713.33333333314.06666666722323.624.085714286累乘和累除的缺陷是不能对负数进行运算因为ln(负数)没有意义本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhuomingwang/archive/2011/02/19/6194556.aspx