with
test as
(
select 1000 as id , 300 as mid from dual
union all
select 1000 as id , 200 as mid from dual
union all
select 1000 as id , 200 as mid from dual
),
test1 as
(
select rownum rn , a.* from test a
)
select a.id - b.mid as result from test1 a , test1 b where b.rn+1 = a.rn(+) order by a.rn
--运行结果
--------------------
700
800
null
你自己把上面的id改为日期相减哈。。
------其他解决方案-------------------- 给你个例子
WITH TEST AS(
SELECT 1 AS N1,2 AS N2 FROM DUAL
UNION ALL
SELECT 3 AS N1,4 AS N2 FROM DUAL
UNION ALL
SELECT 5 AS N1,6 AS N2 FROM DUAL
)
SELECT N1 - LAG(N2,1,0)OVER(ORDER BY N2) FROM TEST ------其他解决方案--------------------