题解 | #获取当前薪水第二多的员工#

获取当前薪水第二多的员工的emp_no以及其对应的薪水salary

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

SELECT s.emp_no,s.salary,
    e.last_name,e.first_name
FROM salaries s
    JOIN employees e USING(emp_no)
WHERE s.salary = (
    SELECT max(salary)
    FROM salaries
    WHERE salary < (
        SELECT max(salary)
        FROM salaries
        WHERE to_date = '9999-01-01'
    )
    and to_date = '9999-01-01'
) and s.to_date = '9999-01-01'

1、找到最大的薪资水平

SELECT max(salary)
        FROM salaries
        WHERE to_date = '9999-01-01'

2、找到第二大的薪资水平

    SELECT max(salary)
    FROM salaries
    WHERE salary < (
        SELECT max(salary)
        FROM salaries
        WHERE to_date = '9999-01-01'
    )
    and to_date = '9999-01-01'

3、输出该员工信息

SELECT s.emp_no,s.salary,
    e.last_name,e.first_name
FROM salaries s
    JOIN employees e USING(emp_no)
WHERE s.salary = (
    SELECT max(salary)
    FROM salaries
    WHERE salary < (
        SELECT max(salary)
        FROM salaries
        WHERE to_date = '9999-01-01'
    )
    and to_date = '9999-01-01'
) and s.to_date = '9999-01-01'
全部评论

相关推荐

10-05 11:11
海南大学 Java
投票
理想江南137:感觉挺真诚的 感觉可以试一试
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务