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

获取当前薪水第二多的员工的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'
全部评论

相关推荐

预计下个星期就能开奖吧,哪位老哥来给个准信
华孝子爱信等:对接人上周说的是这周
点赞 评论 收藏
分享
想润的芹菜人狠话不多:把其中一个老总放中间都会得罪另一个
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务