I am using Oracle 12.1.0.2.0 I want difference in average of current group(partition) - average of previous group(partition) My code to get current group Average is
with rws as (
select rownum x, mod(rownum, 2) y from dual connect by level <= 10
), avgs as (
select x, y, avg(x) over (partition by y) mean from rws
)
select x, y, mean
from avgs;
Now I want something like :
X Y MEAN PREV_MEAN MEAN_DIFF 4 0 6 8 0 6 2 0 6 6 0 6 10 0 6 9 1 5 6 -1 7 1 5 3 1 5 1 1 5 5 1 5 2 2 3 5 -3 3 2 3 5 2 3 1 2 3 4 2 3
AVG( this partitioned group) - Avg( previous partition group) In this case I need ( 5 - 6 ) to compute in GROUP_MEAN_DIFFERENCE column.
Also How can I get mean difference always w.r.t first group. In the example above I need (5 - 6) and (3 - 6)
Can you please assist?