MYSQL:

SELECT  s.emp_no,Y.salary,Y.t_rank
FROM
(SELECT X.salary,CAST((@number := @number+1) AS SIGNED) AS t_rank
FROM
(SELECT DISTINCT salary
FROM salaries
ORDER BY salary DESC) X
JOIN (SELECT @number:=0) AS it) Y
JOIN salaries s
ON Y.salary=s.salary
ORDER BY Y.salary DESC,s.emp_no ASC;

 

posted on 2021-10-12 20:37  Sempron2800+  阅读(102)  评论(0编辑  收藏  举报