题解 | #平均工资#
平均工资
http://www.nowcoder.com/practice/95078e5e1fba4438b85d9f11240bc591
知识点
- 排除在职的最大值和最小值就是salary大于最小值和salary小于最大值
- where后面不能跟聚合函数,所以需要建立一个子查询
代码
select avg(salary) as avg_salary
from salaries
where to_date = '9999-01-01'
and salary < (select max(salary) from salaries where to_date = '9999-01-01')
and salary > (select min(salary) from salaries where to_date = '9999-01-01')