题解 | #智能提示#
查找排除当前最大、最小salary之后的员工的平均工资avg_salary
http://www.nowcoder.com/practice/95078e5e1fba4438b85d9f11240bc591
# **当前**去掉最大最小值的平均值
通过的代码:
select avg(salary) as avg_salary from salaries s1 where s1.to_date > curdate() and s1.salary <> (select min(salary) from salaries where to_date > curdate()) and s1.salary <> (select max(salary) from salaries where to_date > curdate()) ;
两个坑:
1. 当前
2. 最大最小值有重复
### 当前
to_date > curdate()
to_date = '9999-01-01' 没通过
查min(), max()的时候也要加上时间的限制
### 重复的最大最小值
( sum() - min() - max() ) / ( count() - 2 ) 不通过就是因为有重复的最大最小值