码迷,mamicode.com
首页 > 数据库 > 详细

oracle当前月添加一列显示前几个月的累计值

时间:2014-11-11 13:59:56      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   sp   on   2014   art   log   

create table test_leiji(rpt_month_id number(8),
                        current_month NUMBER(12,2));

insert into test_leiji (RPT_MONTH_ID, CURRENT_MONTH) values (200901, 380128.344363);
insert into test_leiji (RPT_MONTH_ID, CURRENT_MONTH) values (200902, 274474.595772);
insert into test_leiji (RPT_MONTH_ID, CURRENT_MONTH) values (200903, 309427.898521);
insert into test_leiji (RPT_MONTH_ID, CURRENT_MONTH) values (200904, 379854.833875);

insert into test_leiji (RPT_MONTH_ID, CURRENT_MONTH) values (201001, 380128.344363);
insert into test_leiji (RPT_MONTH_ID, CURRENT_MONTH) values (201002, 274474.595772);
insert into test_leiji (RPT_MONTH_ID, CURRENT_MONTH) values (201003, 309427.898521);
insert into test_leiji (RPT_MONTH_ID, CURRENT_MONTH) values (201004, 379854.833875);


select  * from  test_leiji t


SELECT rpt_month_id,
       current_month,
       SUM (current_month) OVER (PARTITION BY SUBSTR (rpt_month_id, 1, 4)order by rpt_month_id) sum_month
  FROM test_leiji
  order by rpt_month_id;

显示结果如图:

bubuko.com,布布扣

oracle当前月添加一列显示前几个月的累计值

标签:blog   http   io   ar   sp   on   2014   art   log   

原文地址:http://www.cnblogs.com/shengs/p/4089236.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!