问题描述
我有一张这样的桌子:
我怎样才能完成这个任务?
解决方法
一个表的简单例子,它只有从 0 到 9 的整数值:
select
i,lead(i) over (order by i) as "LEAD",lag(i) over (order by i) as "LAG"
from numm
order by i;
将输出:
+---+------+------+
| i | LEAD | LAG |
+---+------+------+
| 0 | 1 | NULL |
| 1 | 2 | 0 |
| 2 | 3 | 1 |
| 3 | 4 | 2 |
| 4 | 5 | 3 |
| 5 | 6 | 4 |
| 6 | 7 | 5 |
| 7 | 8 | 6 |
| 8 | 9 | 7 |
| 9 | NULL | 8 |
+---+------+------+