Tutorial by Examples

You use the FIRST_VALUE function to determine the first value in an ordered result set, which you identify using a scalar expression. SELECT StateProvinceID, Name, TaxRate,        FIRST_VALUE(StateProvinceID)         OVER(ORDER BY TaxRate ASC) AS FirstValue FROM SalesTaxRate; In this example,...
The LAST_VALUE function provides the last value in an ordered result set, which you specify using a scalar expression. SELECT TerritoryID, StartDate, BusinessentityID,        LAST_VALUE(BusinessentityID)          OVER(ORDER BY TerritoryID) AS LastValue FROM SalesTerritoryHistory; This example...
The LAG function provides data on rows before the current row in the same result set. For example, in a SELECT statement, you can compare values in the current row with values in a previous row. You use a scalar expression to specify the values that should be compared. The offset parameter is the n...
The PERCENT_RANK function calculates the ranking of a row relative to the row set. The percentage is based on the number of rows in the group that have a lower value than the current row. The first value in the result set always has a percent rank of zero. The value for the highest-ranked – or last...
The PERCENTILE_DISC function lists the value of the first entry where the cumulative distribution is higher than the percentile that you provide using the numeric_literal parameter. The values are grouped by rowset or partition, as specified by the WITHIN GROUP clause. The PERCENTILE_CONT functi...

Page 1 of 1