1. /*语法*/  
  2. lag(exp_str,offset,defval) over()  取前
  3. Lead(exp_str,offset,defval) over()  取后
  4. --exp_str要取的列  
  5. --offset取偏移后的第几行数据  
  6. --defval:没有符合条件的默认值  

eg1:

with tmp as(
select '1' id ,'aa' name from dual union all
select '2' id ,'bb' name from dual
union all
select '3' id ,'cc' name from dual
)
select a.*,
lag(name,1) over (order by id asc) lag
from tmp a

运行结果是:

 

 eg2

with tmp as(
select '1' id ,'aa' name from dual union all
select '2' id ,'bb' name from dual
union all
select '3' id ,'cc' name from dual
)
select a.*,
lead(name,1) over (order by id asc) lag
from tmp a