Oracle Rolling or Running totals by month

前端 未结 2 1338
走了就别回头了
走了就别回头了 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条回答
  •  野的像风
    2021-02-15 13:41

    An alternative solution that provides the same rolling totals without the sub query.

    SELECT
            DISTINCT TRUNC(ACTHX.STMT_HX_STMT_DATE,'MM') AS MNTH
            ,count(ACTHX.INVOICE) OVER (ORDER BY TRUNC(ACTHX.STMT_HX_STMT_DATE,'MM')) AS STMTS
        FROM  ACTHX
        ORDER BY
            TRUNC(ACTHX.STMT_HX_STMT_DATE,'MM')
    

提交回复
热议问题