题解 | #获取每个部门中当前员工薪水最高的相关信息#
获取每个部门中当前员工薪水最高的相关信息
http://www.nowcoder.com/practice/4a052e3e1df5435880d4353eb18a91c6
select
d_e_s.dept_no,
d_e_s.emp_no,
m_s.max_salary
from
(
select
d.dept_no,
d.emp_no,
s.salary
from
dept_emp d,
salaries s
where
d.emp_no = s.emp_no
) as d_e_s,
-- d e s 三者关联
(
select
d.dept_no,
max(s.salary) as max_salary
from
dept_emp d,
salaries s
where
d.emp_no = s.emp_no
group by d.dept_no -- 查询出所有部门的最高薪水,通过dept_no分组
) as m_s -- d m_s 两者关联
where
d_e_s.salary = m_s.max_salary
and d_e_s.dept_no = m_s.dept_no
order by
d_e_s.dept_no asc;
d_e_s.dept_no,
d_e_s.emp_no,
m_s.max_salary
from
(
select
d.dept_no,
d.emp_no,
s.salary
from
dept_emp d,
salaries s
where
d.emp_no = s.emp_no
) as d_e_s,
-- d e s 三者关联
(
select
d.dept_no,
max(s.salary) as max_salary
from
dept_emp d,
salaries s
where
d.emp_no = s.emp_no
group by d.dept_no -- 查询出所有部门的最高薪水,通过dept_no分组
) as m_s -- d m_s 两者关联
where
d_e_s.salary = m_s.max_salary
and d_e_s.dept_no = m_s.dept_no
order by
d_e_s.dept_no asc;