Watch the 7.3 Webinar On-Demand
This new release brings updates to Universal Storage, query
optimization, and usability that you won’t want to miss.
Value function. Returns an expression evaluated at some offset after the current row. If there is no such row returns NULL
instead.
LEAD ( expression [, offset]) OVER (
[PARTITION BY (col | expr), ...]
[ORDER BY (col | expr), ...]
)
The result of expression
create table example (a int, b int);
insert into example values(1,2),(2,2),(3,3),(4,3);
select a,lead(a) over(order by (a)) from example;
+------+----------------------------+
| a | lead(a) over(order by (a)) |
+------+----------------------------+
| 1 | 2 |
| 2 | 3 |
| 3 | 4 |
| 4 | NULL |
+------+----------------------------+
select a,lead(a,2) over(order by (a)) from example;
+------+------------------------------+
| a | lead(a,2) over(order by (a)) |
+------+------------------------------+
| 1 | 3 |
| 2 | 4 |
| 3 | NULL |
| 4 | NULL |
+------+------------------------------+