In SQL Server, the GREATEST() function returns the maximum value from a list of one or more expressions.
The GREATEST() function was introduced in SQL Server 2022 (along with the LEAST() function).
In SQL Server, the GREATEST() function returns the maximum value from a list of one or more expressions.
The GREATEST() function was introduced in SQL Server 2022 (along with the LEAST() function).
SQL Server 2022 introduced the LEAST() and GREATEST() functions, which allow us to get the minimum or maximum value from a list of expressions.
The LEAST() function returns the minimum value from a list of one or more expressions.
In SQL Server, PERCENTILE_DISC() is a window function that returns a percentile value based on a discrete distribution of the input column. Basically, it returns the first value in the set whose ordered position is the same or more than the specified fraction.
The output of PERCENTILE_DISC() is equal to a specific column value (unlike the PERCENTILE_CONT() function, which could calculate a value that isn’t in the column).
When we call PERCENTILE_DISC() we specify the percentile to use. It then performs its calculation based on that percentile.
In SQL Server, PERCENTILE_CONT() is a window function that calculates a percentile based on a continuous distribution of the column value.
When we call the function, we specify the percentile to use. It then performs its calculation based on that percentile.
In SQL Server, LEAD() is a window function that allows us to access a value from a later row in the same result set, without the need to perform a self-join.
We specify the row as an offset from the current row. An offset of 1 means it gets the value from the next row, an offset of 2 means two rows forward, and so on.
In SQL Server, LAG() is a window function that enables us to access a value from a previous row in the same result set, without the need to perform a self-join.
We specify the previous row as an offset from the current row. An offset of 1 means the previous row, an offset of 2 means two rows back, and so on.
In SQL Server, the LAST_VALUE() function returns the last value in an ordered set of values.
LAST_VALUE() is a window function that enables us to get a value from the last row of a query result set or partition. This can be useful for when we want to do stuff such as compare a value from the current row with a value in the last row or include it in a calculation.
You may need to explicitly set the window frame if you want LAST_VALUE() to return the actual last value from the partition or result set. That’s because the default window frame ends with the current row. This is covered in the example below.
In SQL Server, FIRST_VALUE() is a window function that returns the first value in an ordered set of values.
Basically, we can use it to get a value from the first row of a query result set or partition. This can be handy if we want to compare a value in the current row with a value in the first row, or use it as part of a calculation.
In SQL Server, PERCENT_RANK() is a window function that calculates and returns the relative rank of a row within a group of rows, expressed as a value between 0 and 1.
In other words, it returns the percentage of partition values less than the value in the current row, excluding the highest value.
In SQL Server, the CUME_DIST() function calculates and returns the cumulative distribution of a value within a group of values. This is the relative position of a specified value in a group of values.