23 Oct 19 · npack · #Snowflake ·   Bookmark  

×

Rows between unbounded preceding and unbounded following in Snowflake - Window Function Syntax

Window Functions:

Window functions are often used for analytics and reporting. You will use a window function to access the values from preceding and following rows in relation to the current row:

select
SUM(x) OVER (PARTITION BY y ORDER BY z ROWS BETWEEN 1 PRECEDING AND 1
FOLLOWING) as ColumnAlias
from Employee;

Other scenarios / examples:

ROWS BETWEEN 10 PRECEDING AND CURRENT ROW
ROWS BETWEEN 2 PRECEDING and 2 FOLLOWING
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
MAX(x) OVER (PARTITION BY y ORDER BY z ROWS BETWEEN 1 PRECEDING AND 1
FOLLOWING) as ColumnAlias
AVG(x) OVER (PARTITION BY y ORDER BY z ROWS BETWEEN 1 PRECEDING AND 1
FOLLOWING) as ColumnAlias

npack

posted on 23 Oct 19

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds

Copied