SQL-54 查找排除当前最大、最小salary之后的员工的平均工资avg_salary。

题目描述

查找排除当前最大、最小salary之后的员工的平均工资avg_salary。
CREATE TABLE `salaries` ( `emp_no` int(11) NOT NULL,
`salary` int(11) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`from_date`));
输出格式:
avg_salary
69462.5555555556
SQL:
select avg(salary)as avg_salary
from salaries
where to_date='9999-01-01'
and salary <>(select max(salary)from salaries where to_date='9999-01-01')
and salary <>(select min(salary)from salaries where to_date='9999-01-01')

  

posted @ 2019-04-22 09:48  柯汐  阅读(545)  评论(0编辑  收藏  举报