select avg(salary) avg_salary
from salaries
where to_date = '9999-01-01'
and salary not in
(
    # 找到max和min
    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'
)

**

总结:

MAX、MIN可以一起在MySQL的查询中使用,但是当作为子查询条件的时候要警惕!!!尤其是子查询包含比较运算符👉NOT IN的时候!!!