I want to calculate the sum 29 previous days in the 30th-day row, I use filter and window function but the FILTER not work,
it still sums from the beginning to the end if I use:
Select *, Sum(quantity) filter (where time between time - interval '29 day' and time) over ()
from t1
it show null column if I use:
Select *, Sum(quantity) filter (where time between time - interval '29 day' and time - interval '1 day') over ()
from t1
Data, I reduce columns for simplicity
Time sum_quantity
2020-01-01 1
2020-01-02 2
2020-01-03 3
2020-01-04 6
....
2020-01-30 100
Data type: Time is date and quantity is integer
Desired result: Should have the same column as first table and add this moving sum column
Day 30 = total quantity of day 1 to day 29, for every 30 days
How to fix this