题解 | #查找排除当前最大、最小salary之后的员工的平均工资avg_salary#
先找到最大值和最小值(用开窗函数排序),剔除后取平均。
select avg(t1.salary) from (select salary, dense_rank() over (order by salary) as minSalary, dense_rank() over (order by salary desc ) as maxSalary from salaries where to_date = '9999-01-01') as t1 where t1.minSalary <> 1 and t1.maxSalary <> 1;