This Window function operates on a set of rows for the query provided. It returns the value for each row using multiple rows or only one row. The set of the row is determined by the OVER() clause. These functions are used to find out the first value, last value, next value, and previous value in the set of rows. These value window functions are also known as Analytic Window functions.
The below table list shows the different types of Value Window functions with their argument type and description –
Window Function | Argument Type | Return Type | Description |
LAG() | Any supported Drill data types | Same as the expression type | The LAG() window function is used to fetch the previous row data along with the current row data. |
LEAD() | Any supported Drill data types | Same as the expression type | The LEAD()window function is used to fetch the subsequent row data along with the current row data. If no row exists, null is returned. |
FIRST_VALUE | Any supported Drill data types | Same as the expression type | The FIRST_VALUE window function returns the value the first value from the specified column with the current row in the dataset. |
LAST_VALUE | Any supported Drill data types | Same as the expression type | The LAST_VALUE window function returns the value the last value from the specified column with the current row in the dataset. |
These are the main four value window function that is used in SQL. Let’s look at the other articles to get an in-depth understanding of these functions using different explanatory examples.
Other SQL topics to check out:
- What is RDBMS (Relational Database Management System)?
- SQL SELECT Statement
- SQL INSERT INTO SELECT Statement
- SQL ALL Operator
- SQL WHERE Clause
- SQL AND Operator
- SQL OR Operator
Follow us on Twitter, Facebook, Linkedin, and Tableau Public to stay updated with our latest blog and what’s new in Tableau.
If you are looking forward to getting your data pipeline built and setting up the dashboard for business intelligence, book a call now from here.