scott@TEST>select deptno,ename,hiredate,sal,avg(sal) over(partition by deptno order by sal rows BETWEEN 1 PRECEDING AND 1 FOLLOWING) avg from emp;
DEPTNO ENAME HIREDATE SAL AVG
---------- ------------------------------ ------------------- ---------- ----------
10 MILLER 1982-01-23 00:00:00 1300 1875
10 CLARK 1981-06-09 00:00:00 2450 2916.66667
10 KING 1981-11-17 00:00:00 5000 3725
20 SMITH 1980-12-17 00:00:00 800 950
20 ADAMS 1987-05-23 00:00:00 1100 1625
20 JONES 1981-04-02 00:00:00 2975 2358.33333
20 SCOTT 1987-04-19 00:00:00 3000 2991.66667
20 FORD 1981-12-03 00:00:00 3000 3000
30 JAMES 1981-12-03 00:00:00 950 1100
30 MARTIN 1981-09-28 00:00:00 1250 1150
30 WARD 1981-02-22 00:00:00 1250 1333.33333
30 TURNER 1981-09-08 00:00:00 1500 1450
30 ALLEN 1981-02-20 00:00:00 1600 1983.33333
30 BLAKE 1981-05-01 00:00:00 2850 2225
从输出的结果可以看出,分析函数对每一组中的每一行的输出结果是把它自己与它的上一行和下一行这三行求平均值。
分析函数太多,这里就不一一介绍功能了,有兴趣的同学可以点开上面的连接,去查看对应的功能。