I have a table DATE_VALUE like this:
Date Value
---- -----
01/01/2012 1.5
02/01/2012 1.7
03/01/2012 1.3
04/01/2012 2.1
05/01/2012 3.4
I want to calculate variance between differences of value between 2 consecutive dates. However this simple query does not work:
select variance(lead( value,1) OVER (order by date) - value)
from DATE_VALUE
I got an error:
ORA-30483: window functions are not allowed here 30483. 00000 - "window functions are not allowed here" *Cause: Window functions are allowed only in the SELECT list of a query. And, window function cannot be an argument to another window or group function.
The query works fine if I move the variance function out of the query:
select variance(difvalue) from (
select lead( value,1) OVER (order by rundate) - value as difvalue
from DATE_VALUE
);
I wonder if there is any way to modify the query such that there is no sub-query used?