代码拉取完成,页面将自动刷新
查找排除当前最大、最小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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。