2

Combination of window function with datetime:

Is there is something like this in Snowflake?:

select t.*,
       sum(qty) over (partition by article
                      order by date
                      range between interval '27 day' preceding and current row
                     ) as sum_qty_28_days
from t;

taken from:

sum last n days quantity using sql window function

Michael D
  • 1,711
  • 4
  • 23
  • 38

2 Answers2

2

From Snowflake's documentation

For sliding window frames:

ROWS is inclusive and is always relative to the current row.

RANGE is not supported.

Your best bet is a correlated subquery approach used in the link you shared.

Radagast
  • 5,102
  • 3
  • 12
  • 27
-1

In snowflake, you can use the following query

select t.*,
       sum(qty) over (partition by article
                      order by date
                      rows between 27 preceding and current row
                     ) as sum_qty_28_days
from t;
hawkhunt
  • 5
  • 2