select avg(salary) as avg_salary
from salaries
where 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')
and to_date = '9999-01-01';

这道题应该有简单的方法,但是,以我目前所掌握的知识,只能一层一层的剥开这个问题来分析。

其中,需要注意的几个点:

  1. 聚类函数只能在查询语句中使用
  2. (not) in 后面如果有查询语句,那么查询语句只能包含一列。