当前所在位置:珠峰网资料 >> 计算机 >> Oracle认证 >> 正文
oracle用sum函数实现累加(一)
发布时间:2010/10/6 10:36:12 来源:www.xue.net 编辑:城市总裁吧
 ====================Question=========================

  jmbdat    dayt    y       mon

  27-9月 -07 2033.2 2007 200709

  28-9月 -07 2750.28 2007 200709

  29-9月 -07 2885.68 2007 200709

  30-9月 -07 2556.68 2007 200709

  01-10月-07 2903.04 2007 200710

  02-10月-07 1002.96 2007 200710

  03-10月-07 1038.24 2007 200710

  对上边的表用sql处理下 变成下面的

  jmbdat    dayt    y       mon       mont

  27-9月 -07 2033.2 2007 200709    2033.2

  28-9月 -07 2750.28 2007 200709    4783.28

  29-9月 -07 2885.68 2007 200709    7669.16

  30-9月 -07 2556.68 2007 200709    20225.84

  01-10月-07 2903.04 2007 200710    2903.04

  02-10月-07 1002.96 2007 200710    3906

  03-10月-07 1038.24 2007 200710    4944.24

  该怎么做啊?

  ==================Solution=========================

  SQL:

  select tt.*,

  sum(tt.dayt) over (partition by tt.mon order by tt.jmbdat,tt.y,tt.mon) as sum_dayt

  from tablename tt;

  Result :

  JMBDAT            DAYT          Y MON      SUM_DAYT

  ----------- ---------- ---------- ------ ----------

  2007-9-27       2033.2       2007 200709     2033.2

  2007-9-28      2750.28       2007 200709    4783.48

  2007-9-29      2885.68       2007 200709    7669.16

  2007-9-30      2556.68       2007 200709   10225.84

  2007-10-1      2903.04       2007 200710    2903.04

  2007-10-2      1002.96       2007 200710       3906

  2007-10-7      1038.24       2007 200710    4944.24

  7 rows selected

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved