R: Total in the last 365 days window by month

问题: Sorry if i did something wrong in my first time using stackoverflow, and sorry everyone of you that waste time with me. I talked to some users and i can do something differ...

问题:

Sorry if i did something wrong in my first time using stackoverflow, and sorry everyone of you that waste time with me. I talked to some users and i can do something different. defaults(today -60 until -365) after that time will have another column called loss, to take the rest of the values.

Thanks everyone who helped me! problem solved!

            CASE
            WHEN TO_DATE(SYSDATE,'DD/MM/YY')-425 <= TO_DATE(TRIM(DT_TRANSACAO),'DD/MM/YY')
            THEN SUM(VL_VENCIDO)
            ELSE 0
            END AS   VL_VENCIDO, ---defaults(today -60 until -365 days ago) 
            CASE
            WHEN TO_DATE(SYSDATE,'DD/MM/YY')-425 > TO_DATE(TRIM(DT_TRANSACAO),'DD/MM/YY')
            THEN SUM(VL_VENCIDO)
            ELSE 0
            END AS   VL_PDD, --loss more than 425 days ago
         ---acumulated loss and defaults
        sum(VL_PDD) over (order by YEAR, MONTH) AS VL_AC_PDD, 
        sum(VL_VENCIDO) over (order by YEAR, MONTH) AS VL_AC_INADI

Thanks folks! And sorry again english is not my best skill!


回答1:

  CASE
            WHEN TO_DATE(SYSDATE,'DD/MM/YY')-425 <= TO_DATE(TRIM(DT_TRANSACAO),'DD/MM/YY')
            THEN SUM(VL_VENCIDO)
            ELSE 0
            END AS   VL_VENCIDO, ---defaults(today -60 until -365 days ago) 
            CASE
            WHEN TO_DATE(SYSDATE,'DD/MM/YY')-425 > TO_DATE(TRIM(DT_TRANSACAO),'DD/MM/YY')
            THEN SUM(VL_VENCIDO)
            ELSE 0
            END AS   VL_PDD, --loss more than 425 days ago
         ---acumulated loss and defaults
        sum(VL_PDD) over (order by YEAR, MONTH) AS VL_AC_PDD, 
        sum(VL_VENCIDO) over (order by YEAR, MONTH) AS VL_AC_INADI
  • 发表于 2019-01-13 15:34
  • 阅读 ( 196 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除