Fetch the repository succeeded.
查找排除当前最大、最小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`));
select avg(salary) avg_salary from salaries s where to_date = '9999-01-01' and salary not in (select min(salary) from salaries where s.to_date = '9999-01-01') and salary not in (select max(salary) from salaries where s.to_date = '9999-01-01')
使用min和max函数获得最大值最小值,而后用not in将最大值最小值记录去除,求平均
1、获得salary最大值maxRecord最小值minRecord记录(逻辑上需要按照当前时间的salary进行筛选)
select max(salary) from salaries where s.to_date = '9999-01-01')
select min(salary) from salaries where s.to_date = '9999-01-01')
2、去除最大值最小值记录 t1
select * from salaries where to_data = '9999-01-01' and salary not in maxRecord and salary not in minRecord
3、对上面的临时表求平均值即可
select avg(salary) from t1
Sign in for post a comment
Comment ( 0 )