题解 | #获取员工其当前的薪水比其manager当前薪水还高的相关信息#
获取员工其当前的薪水比其manager当前薪水还高的相关信息
http://www.nowcoder.com/practice/f858d74a030e48da8e0f69e21be63bef
思路:做两个表,一个用来存员工信息及薪水,另一个用来存manager信息及薪水,然后通过where筛选出薪水大于manager的员工,查询出对应信息
select sde.emp_no as emp_no, sdm.emp_no as manager_no, sde.salary as emp_salary, sdm.salary as manager_salary
from
(select s.salary, s.emp_no, de.dept_no
from dept_emp de join salaries s
on de.emp_no = s.emp_no
and s.to_date = '9999-01-01'
) as sde,
(select s.salary, s.emp_no, dm.dept_no
from dept_manager dm join salaries s
on dm.emp_no = s.emp_no
and s.to_date = '9999-01-01'
) as sdm
where sde.dept_no = sdm.dept_no and sde.salary > sdm.salary
SQL练习 文章被收录于专栏
已完成牛客的SQL练习。接下来是算法的练习