题解 | #题解#

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

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

-- 创建临时表 tem_1,选择除部门经理外其他员工的员工号、部门号和薪水
with tem_1 as ( 
    select a.emp_no, a.dept_no, sa.salary 
    from (
        select de.emp_no, de.dept_no
        from dept_emp de, dept_manager dm
        where de.dept_no = dm.dept_no and de.emp_no != dm.emp_no
    ) a, salaries sa 
    where a.emp_no = sa.emp_no 
),
-- 创建临时表 tem_2,选择部门经理的员工号、部门号和薪水
tem_2 as (
    select b.emp_no, b.dept_no, sa.salary 
    from (
        select de.emp_no, de.dept_no
        from dept_emp de, dept_manager dm
        where de.dept_no = dm.dept_no and de.emp_no = dm.emp_no
    ) b, salaries sa 
    where b.emp_no = sa.emp_no 
)
-- 选取 tem_1 和 tem_2 中符合薪水高于部门经理的员工号、部门经理号以及员工和部门经理的薪水
select t1.emp_no, t2.emp_no as manager_no, t1.salary as emp_salary, t2.salary as manager_salary 
from tem_1 t1, tem_2 t2 
where t1.dept_no = t2.dept_no and t1.salary > t2.salary

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 16:15
我应届生,去年10月份开始在这家公司实习,到今年10月份正好一年想(实习+试用期),在想要不要提前9月份就离职,这样好找工作些,但又差一个月满一年,又怕10月份国庆回来离职,容易错过了下半年的金九银十,到年底容易gap到年后
小破站_程序员YT:说这家公司不好吧,你干了快一年 说这家公司好吧,你刚毕业就想跑路说你不懂行情吧,你怕错过金九银十说 你懂行情吧,校招阶段在实习,毕业社招想换工作 哥们,我该怎么劝你留下来呢
应届生,你找到工作了吗
点赞 评论 收藏
分享
06-12 16:23
已编辑
小米_软件开发(准入职员工)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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