Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: a sql question
Yes, val - lag(val) over(order by id) is what I was looking for.
Thanks.
G
>
> SQL> with t as(
> 2 select 1 id,100 val from dual union all
> 3 select 2,101 from dual union all
> 4 select 3,200 from dual union all
> 5 select 4,300 from dual)
> 6 select id,new_val as computed_value from (
> 7 SELECT id, val, val - lag(val) over(order by id) new_val
> 8 from t)
> 9 where new_val is not null
> 10 /
>
> ID COMPUTED_VALUE
> ---------- --------------
> 2 1
> 3 99
> 4 100
>
> Best regards
>
> Maxim- Hide quoted text -
>
> - Show quoted text -
Received on Tue Mar 06 2007 - 15:10:16 CST
![]() |
![]() |