Data and AI SQL Window Functions
Data and AI SQL Window Functions
SQL
Window Functions
Shwetank Singh
GritSetGrow - GSGLearn.com
gsglearn.com
Data and AI
NTH_VALUE
Retrieves the n-th value in an ordered
partition of a result set. Useful for accessing
specific rows within a window frame.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
CUME_DIST
Calculates the cumulative distribution of a
value within a group of values. It returns the
relative position of a value in a group.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
PERCENT_RANK
Computes the relative rank of a row within a
partition as a percentage, ranging from 0 to
1.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
PERCENTILE_CONT
A continuous percentile function that
calculates a specific percentile value within a
group, interpolating between values if
necessary.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
PERCENTILE_DISC
A discrete percentile function that returns the
first value in the ordered set of values that is
greater than or equal to the specified percentile.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
FIRST_VALUE
Returns the first value in an ordered partition
of a result set.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
LAST_VALUE
Returns the last value in an ordered partition
of a result set.
NTILE
Distributes the rows in an ordered partition into a
specified number of approximately equal groups,
assigning a bucket number to each row.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
LAG
Accesses data from a previous row in the
same result set without the use of a self-join.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
LEAD
Accesses data from a subsequent row in the
same result set without the use of a self-join.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
ROW_NUMBER
Assigns a unique sequential integer to rows
within a partition of a result set, starting at 1
for the first row in each partition.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
RANK
Assigns a rank to each row within a partition
of a result set, with gaps in rank values when
there are ties.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
DENSE_RANK
Similar to RANK(), but without gaps in rank
values when there are ties.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
SUM
Calculates the cumulative sum of a numeric
column over a specified window frame.
Shwetank Singh
GritSetGrow - GSGLearn.com
Data and AI
AVG
Calculates the average of a numeric column
over a specified window frame.
Shwetank Singh
GritSetGrow - GSGLearn.com