题解 | #获比其manager当前薪还高的相关信息#

获取员工其当前的薪水比其manager当前薪水还高的相关信息

https://www.nowcoder.com/practice/f858d74a030e48da8e0f69e21be63bef

一开始想直接连接到一块,写的一半发现写的太乱了,然后还是老实的构造新表做了

基本思想就是构造出带有工资的员工表和部门经理表,然后连接比较即可

with table1 as
(select de.emp_no emp_no,dept_no,salary
 	from dept_emp de inner join salaries s on de.emp_no=s.emp_no),
table2 as
(select dept_no,dm.emp_no manager_no,salary
	from dept_manager dm inner join salaries s on dm.emp_no=s.emp_no )

select emp_no,manager_no,t1.salary emp_salary,t2.salary manager_salary
from table1 t1 left join table2 t2 on t1.dept_no =t2.dept_no
where t1.salary>t2.salary

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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