题目描述
查找排除当前最大、最小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`));
输出格式:
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')