Oracle Rolling or Running totals by month

前端 未结 2 1349
走了就别回头了
走了就别回头了 2021-02-15 12:50

Goal: Rolling/Running total for all statements at the end of each month.

Code:

select 
    TRUNC(ACTHX.STMT_HX_STMT_DATE, \'MM\') AS MNTH, 
    COUNT(ACT         


        
2条回答
  •  猫巷女王i
    2021-02-15 13:48

    It sounds like you want the running total. You can use the analytic SUM function for that.

    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
    

提交回复
热议问题