--■■■First_Valueを使う方法(10g以降)■■■
with hoge as
(select 1 as ID,0 as VI,0 as C1 from dual
union select 1,1,10 from dual
union select 1,2,20 from dual
union select 1,3,25 from dual
union select 1,4,50 from dual
union select 2,1,100 from dual
union select 2,2,200 from dual
union select 3,3,500 from dual)
select ID,VI,C1,
case VI when 1 then null
else c1- First_Value(case VI when 1 then C1 end ignore nulls)
over(partition by ID order by VI Rows between Unbounded
Preceding and Unbounded Following) end as C2
from hoge;
--■■■min関数を使う方法■■■
with hoge as
(select 1 as ID,0 as VI,0 as C1 from dual
union select 1,1,10 from dual
union select 1,2,20 from dual
union select 1,3,25 from dual
union select 1,4,50 from dual
union select 2,1,100 from dual
union select 2,2,200 from dual
union select 3,3,500 from dual)
select ID,VI,C1,
case VI when 1 then null
else c1- min(case VI when 1 then C1 end) over(partition by ID) end as C2
from hoge;