leetcode 的 sql 题目有一些涉及到排名问题,mysql并没有内置rank函数。
主要参考blog,并总结要点
https://www.jianshu.com/p/bb1b72a1623e
https://blog.csdn.net/xxzhangx/article/details/78170019
1. self join
select a.XX
from table a, table b
where a.XX = b.xx
2. temp table
select count(*) FROM (SELECT distinct zz FROM table) tmp WHERE s >= Score) as YYY
FROM table
主要特征在于 select something from another table originated from the former selection and the result of the former selection is shown as table tmp
3. user variable
select
Score,
@rank := @rank + (@prev != (@prev := Score)) as Rank
from
Scores,
(select @rank := 0,