/*语法*/ lag(exp_str,offset,defval) over() Lead(exp_str,offset,defval) over() --exp_str要取的列 --offset取偏移后的第几行数据 --defval:没有符合条件的默认值
with x0 as (select '1'as aa ,to_date('2018-01-01','yyyy-mm-dd') as 日期 from dual union all select '2' as aa,to_date('2018-01-15','yyyy-mm-dd') as 日期 from dual union all select '3' as aa, to_date('2018-01-26','yyyy-mm-dd') as 日期 from dual ) select aa ,日期, lead(日期,1,null) over (order by 日期), lag(日期) over (order by 日期) from x0