oracle average
时间: 2023-11-01 20:57:28 浏览: 81
在Oracle中,avg函数用于计算给定列的平均值。以下是一些示例用法:
1. 基本用法:计算employees表中薪水列的平均值。
```
select avg(salary) as "Average" from employees;
```
2. 结合分析函数:按照manager_id进行排序,并以部门分组计算薪水的平均值。
```
select manager_id, last_name, hire_date, salary, avg(salary) over(partition by manager_id) as c_mavg
from employees
order by manager_id, hire_date, salary;
```
或者等价写法:
```
select a.manager_id, a.last_name, a.hire_date, a.salary, b.c_mavg
from employees a, (select manager_id, avg(salary) c_mavg from employees group by manager_id) b
where a.manager_id = b.manager_id
order by manager_id, hire_date, salary;
```
请问还有其他相关问题吗?
相关问题:
1. 如何在Oracle中计算其他统计函数,例如sum和count?
2. avg函数在Oracle中返回的数据类型是什么?
3. 如何处理含有null值的列的平均值计算?
阅读全文