How to calculate total accumulated of 365 days joining two different years?

2

I'm trying to check the cumulative total for a certain amount, which starts in September of a year and runs through August of the following year, and then resumes. I'm doing this with a long historical series, so it would be n sums for various data.

I've tried this sql:

SELECT ad.cod, ad.data, 
       SUM(ad.value)
            OVER(ORDER BY ad.data ROWS BETWEEN 364 PRECEDING AND CURRENT ROW) AS sum_value
FROM mytable ad 
    
asked by anonymous 15.02.2017 / 13:00

2 answers

0
select
    to_char(date_trunc('year', ad.data - interval '8 months'), 'YYYY'),
    sum(ad.value)
from mytable ad
group by 1
    
15.02.2017 / 17:05
0

This second came perfectly, I just have to check how to start the initial month to start the calculation.

Thank you very much

    
15.02.2017 / 23:00