题解 | #获取每个部门中当前员工薪水最高的相关信息#

获取每个部门中当前员工薪水最高的相关信息

http://www.nowcoder.com/practice/4a052e3e1df5435880d4353eb18a91c6

因为聚合函数通过作用于一组数据而只返回一个单个值,因此,在SELECT语句中出现的元素要么为一个聚合函数的输入值,要么为GROUP BY语句的参数,否则会出错。

elect de.dept_no,s.emp_no,s.salary as maxSalary from
dept_emp de inner join salaries s on de.emp_no = s.emp_no and
de.to_date='9999-01-01' and s.to_date='9999-01-01'
where s.salary in #子查询中查询出工资的最大值
(select max(ss.salary) as maxSalary from dept_emp d inner join salaries ss
on d.emp_no = ss.emp_no and d.to_date='9999-01-01'
and ss.to_date='9999-01-01' and de.dept_no=d.dept_no
)
order by de.dept_no

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务