自连接查询,与前面的题目一样的思路

SELECT
    s1.emp_no,
    s1.salary,
    COUNT(DISTINCT s2.salary) AS t_rank
FROM
    salaries s1 inner join
    salaries s2
on s2.salary >= s1.salary
WHERE
    s1.to_date = '9999-01-01'
AND s2.to_date = '9999-01-01'
GROUP BY
    s1.emp_no
ORDER BY
    s1.salary DESC,
    s1.emp_no ASC;

参考:https://blog.nowcoder.net/n/cf64ae022bd44ab8a5b100253bd8a734