目标:每个月末所有报表的滚动/运行总计。
代码:
select
TRUNC(ACTHX.STMT_HX_STMT_DATE, 'MM') AS MNTH,
COUNT(ACTHX.INVOICE) as STMTS
from ACTHX
group by
TRUNC(ACTHX.STMT_HX_STMT_DATE, 'MM')
ORDER BY
TRUNC(ACTHX.STMT_HX_STMT_DATE, 'MM')
电流输出:
MNTH STMTS
7/1/2009 1
10/1/2010 4
6/1/2011 26
9/1/2011 211
10/1/2011 163
11/1/2011 119
所需的输出:
MNTH STMTS
7/1/2009 1
10/1/2010 5
6/1/2011 31
9/1/2011 242
10/1/2011 405
11/1/2011 524
最佳答案
听起来您想要总的运行量。您可以为此使用解析SUM
函数。
select mnth,
sum(stmts) over (order by mnth) stmts
from (select TRUNC(ACTHX.STMT_HX_STMT_DATE, 'MM') AS MNTH,
COUNT(ACTHX.INVOICE) as STMTS
from ACTHX
group by TRUNC(ACTHX.STMT_HX_STMT_DATE, 'MM'))
ORDER BY mnth
关于sql - Oracle每月滚动或运行总计,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8931975/