题解 | #对所有员工的薪水按照salary进行按照1-N的排名#
对所有员工的薪水按照salary进行按照1-N的排名
http://www.nowcoder.com/practice/b9068bfe5df74276bd015b9729eec4bf
还有一种写法,作用相当于是窗口函数 DENSE_RANK()
SELECT emp_no,salary, CASE WHEN @prevRank = salary THEN @curRank WHEN @prevRank := salary THEN @curRank := @curRank + 1 END AS t_rank FROM salaries, (SELECT @curRank :=0, @prevRank := NULL) r ORDER BY salary desc,emp_no