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

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

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

select
    t1.emp_no,
    t2.emp_no,
    emp_salary,
    t2.salary
from
    (
        select
            de.emp_no emp_no,
            s1.salary emp_salary,
            de.dept_no dept_no
        from
            dept_emp de
            left join salaries s1 on de.emp_no = s1.emp_no
    ) as t1
    left join (
        select
            dept_no,
            salary,
            dm.emp_no emp_no
        from
            dept_manager dm
            inner join salaries s2 on dm.emp_no = s2.emp_no
    ) as t2 on t1.dept_no = t2.dept_no
where
    t1.emp_salary > t2.salary

先连接表得到员工的工资,再连接表的到经理的工资,根据部门号将两个表连接,最后再where一下就好了

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 12:10
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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