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

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;

显示结果如图:

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。