SELECT manager_id, last_name, hire_date, salary,
AVG(salary) OVER (PARTITION BY manager_id ORDER BY hire_date
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS c_mavg
FROM employees;Use the PARTITION BY clause to partition the query result set into groups
based on one or more value_expr. If you omit this clause, the function treats
all rows of the query result set as a single group.
You can specify multiple analytic functions in the same query, each with the
same or different PARTITION BY keys.
AVG(salary) OVER (PARTITION BY manager_id ORDER BY hire_date
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS c_mavg
FROM employees;Use the PARTITION BY clause to partition the query result set into groups
based on one or more value_expr. If you omit this clause, the function treats
all rows of the query result set as a single group.
You can specify multiple analytic functions in the same query, each with the
same or different PARTITION BY keys.
就是按照这个字段分组,
比如
id order
1 1
1 2
1 3
2 4
2 5
2 6
如果按id PARTITION,则可以出现
1 1
1 2
1 3
2 1
2 2
2 3
其实,你做实验一看就明白。
如:select sum(sal) over(partition by dept_id order by sal) from table_name