题解 | #平均工资#
平均工资
http://www.nowcoder.com/practice/95078e5e1fba4438b85d9f11240bc591
思路:按照题意使用 MAX/MIN + NOT IN 去除掉最大最小salary,然后算平均值。
- 查询在职员工的最大salary
select max(salary)
from salaries
where to_date = '9999-01-01'
- 查询在职员工的最小salary
select min(salary)
from salaries
where to_date = '9999-01-01'
- 查询在职员工的平均salary
select avg(salary)
from salaries
where to_date = '9999-01-01'
and salary not in (select max(salary) from salaries where to_date = '9999-01-01')
and salary not in (select min(salary) from salaries where to_date = '9999-01-01')
SQL练习 文章被收录于专栏
已完成牛客的SQL练习。接下来是算法的练习