题解 | #对所有员工的薪水按照salary降序进行1-N的排名#
对所有员工的薪水按照salary降序进行1-N的排名
http://www.nowcoder.com/practice/b9068bfe5df74276bd015b9729eec4bf
答案:
SELECT emp_no,salary, CASE WHEN @salary=s.salary THEN @rank WHEN @salary:=s.salary THEN @rank:=@rank+1 END as t_rank from salaries s,(SELECT @rank:=0,@salary:=NULL) a ORDER BY salary DESC;