Collections:
LEAD() - N-Row after Current Row within Window
How to evaluate a field expression on n-row after the current row in the current result set window using the LEAD() function?
✍: FYIcenter.com
LEAD(exp, n, default) is a MySQL built-in window function that
evaluates a field expression on n-row after the current row
in the current result set window.
For example:
SELECT help_topic_id AS tip, help_category_id AS cid, name, LEAD(name, 2, NULL) OVER w FROM mysql.help_topic WINDOW w AS (PARTITION BY help_category_id); -- +-----+-----+----------------+-----------------------------+ -- | tip | cid | name | LEAD(name, 2, NULL) OVER w | -- +-----+-----+----------------+-----------------------------+ -- | 0 | 1 | HELP_DATE | NULL | -- | 1 | 1 | HELP_VERSION | NULL | -- | 2 | 2 | AUTO_INCREMENT | TINYINT | -- | 6 | 2 | BIT | BOOLEAN | -- | 7 | 2 | TINYINT | SMALLINT | -- | 8 | 2 | BOOLEAN | MEDIUMINT | -- | 9 | 2 | SMALLINT | INT | -- | 10 | 2 | MEDIUMINT | INTEGER | -- ... -- +-----+-----+----------------+-----------------------------+
Reference information of the LEAD() function:
LEAD(exp, n, default): val Evaluates a field expression on n-row after the current row in the current result set window. Arguments, return value and availability: exp: Required. The field expression to be evaluated. n: Optional. Default is 1. The number of rows leading the current row. default: Optional. Default is NULL. The default value for non-existing rows. val: Return value. The exp value on n-row after the current row. Available since MySQL 8.
Related MySQL functions:
⇒ NTH_VALUE() - N-th Value of Result Set Window
⇐ LAST_VALUE() - Last Value of Result Set Window
2024-09-28, 1022🔥, 0💬
Popular Posts:
What Is "mysqld" in MySQL? "mysqld" is MySQL server daemon program which runs quietly in background ...
How to set database to be READ_ONLY in SQL Server? Databases in SQL Server have two update options: ...
Where Is the Export Dump File Located in Oracle? If you are not specifying the dump directory and fi...
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
Is PL/SQL Language Case Sensitive in Oracle? PL/SQL language is not case sensitive: Reserved words a...