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